none
Unresolved external error for fopen(), etc RRS feed

  • Question

  • Hello,

    Working on a project to develop an NDIS protocol driver. Started with the base code from MS. Want the driver to write to a file when it gets loaded. Added some code to open a file with fopen() and then code has an fwrite(). To build the driver, used the DDK command wndow, switched to my folder with source code and SOURCES file, and did a "build -cefbw". Got unresolved external errors for the fopen and fwrite. Added the line "USE_LIBCMT=1" to the SOURCES file. This did not help either. Don't understand why the standard MT C library is not getting linked in (with and without the USE line in the SOURCES file).

    Below are the contents of the log file buildfre_win7_x86.log.

    All help will be appreciated.

    Thanks in advance.

    - K

    BUILD: Computing Include file dependencies:
    BUILD: Examining c:\micon\myndis\sys directory for files to compile.
    oacr invalidate root:x86fre /autocleanqueue
    1>Compiling and Linking c:\micon\myndis\sys *************
    1>'nmake.exe /nologo BUILDMSG=Stop. -i BUILD_PASS=PASS2 LINKONLY=1 NOPASS0=1 MAKEDIR_RELATIVE_TO_BASEDIR='
    1>C:\WinDDK\7600.16385.1\Bin\x86\oacr\oacrcl /Ii386 /I. /Ic:\micon\myndis\sys\objfre_win7_x86\i386 /IC:\WinDDK\7600.16385.1\inc\api /IC:\WinDDK\7600.16385.1\inc\api /IC:\WinDDK\7600.16385.1\inc\ddk /IC:\WinDDK\7600.16385.1\inc\ddk /IC:\WinDDK\7600.16385.1\inc\crt /D_X86_=1 /Di386=1 /DSTD_CALL /DCONDITION_HANDLING=1 /DNT_UP=1 /DNT_INST=0 /DWIN32=100 /D_NT1X_=100 /DWINNT=1 /D_WIN32_WINNT=0x0601 /DWINVER=0x0601 /D_WIN32_IE=0x0800 /DWIN32_LEAN_AND_MEAN=1 /DDEVL=1 /D__BUILDMACHINE__=WinDDK /DFPO=0 /DNDEBUG /D_DLL=1 /DNDEBUG -DNDIS_WDM=1 -DNDIS51=1 /DNTDDI_VERSION=0x06010000 /c /Zc:wchar_t- /Zl /Zp8 /Gy /Gm- -cbstring /WX /W4 /WX /Gz /hotpatch /EHs-c- /GR- /GF /GS /Zi /Oxs /Oy- /Zi /Fdc:\micon\myndis\sys\objfre_win7_x86\i386\ /DKMDF_MAJOR_VERSION_STRING=01 /DKMDF_MINOR_VERSION_STRING=009 /wd4603 /wd4627 /typedil- /FIC:\WinDDK\7600.16385.1\inc\api\warning.h /Yuprecomp.h /Fpc:\micon\myndis\sys\objfre_win7_x86\i386\precomp.pch /Ylndisprot /Ycprecomp.h /Fpc:\micon\myndis\sys\objfre_win7_x86\i386\precomp.pch /Fo"c:\micon\myndis\sys\objfre_win7_x86\i386\precomp.obj" /Tc
    1>#include "precomp.h"
    1>Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.207 for 80x86
    1>Copyright (C) Microsoft Corporation.  All rights reserved.
    1>cl 
    1> /Ii386
    1> /I.
    1> /Ic:\micon\myndis\sys\objfre_win7_x86\i386
    1> /IC:\WinDDK\7600.16385.1\inc\api
    1> /IC:\WinDDK\7600.16385.1\inc\api
    1> /IC:\WinDDK\7600.16385.1\inc\ddk
    1> /IC:\WinDDK\7600.16385.1\inc\ddk
    1> /IC:\WinDDK\7600.16385.1\inc\crt
    1> /D_X86_=1
    1> /Di386=1
    1> /DSTD_CALL
    1> /DCONDITION_HANDLING=1
    1> /DNT_UP=1
    1> /DNT_INST=0
    1> /DWIN32=100
    1> /D_NT1X_=100
    1> /DWINNT=1
    1> /D_WIN32_WINNT=0x0601
    1> /DWINVER=0x0601
    1> /D_WIN32_IE=0x0800
    1> /DWIN32_LEAN_AND_MEAN=1
    1> /DDEVL=1
    1> /D__BUILDMACHINE__=WinDDK
    1> /DFPO=0
    1> /DNDEBUG
    1> /D_DLL=1
    1> /DNDEBUG
    1> -DNDIS_WDM=1
    1> -DNDIS51=1
    1> /DNTDDI_VERSION=0x06010000
    1> /c
    1> /Zc:wchar_t-
    1> /Zl
    1> /Zp8
    1> /Gy
    1> /Gm-
    1> -cbstring
    1> /WX
    1> /W4
    1> /WX
    1> /Gz
    1> /hotpatch
    1> /EHs-c-
    1> /GR-
    1> /GF
    1> /GS
    1> /Zi
    1> /Oxs
    1> /Oy-
    1> /Zi
    1> /Fdc:\micon\myndis\sys\objfre_win7_x86\i386\
    1> /DKMDF_MAJOR_VERSION_STRING=01
    1> /DKMDF_MINOR_VERSION_STRING=009
    1> /wd4603
    1> /wd4627
    1> /typedil-
    1> /FIC:\WinDDK\7600.16385.1\inc\api\warning.h
    1> /Ylndisprot /Ycprecomp.h /Fpc:\micon\myndis\sys\objfre_win7_x86\i386\precomp.pch /Fo"c:\micon\myndis\sys\objfre_win7_x86\i386\precomp.obj"
    1>pch_hdr.src
    1> rc.exe -l 409 -DSXS_PROCESSOR_ARCHITECTURE="""x86"""  -DSXS_TARGET="""ndisprot.sys"""   -DSYSTEM_COMPATIBLE_ASSEMBLY_NAME="""Microsoft.Windows.SystemCompatible"""  -DLSYSTEM_COMPATIBLE_ASSEMBLY_NAME=L"""Microsoft.Windows.SystemCompatible"""   -DSXS_ASSEMBLY_VERSION=""""""  /r /fo c:\micon\myndis\sys\objfre_win7_x86\i386\ndisprot.res /D_X86_=1 /Di386=1  /DSTD_CALL /DCONDITION_HANDLING=1 /DNT_UP=1  /DNT_INST=0 /DWIN32=100 /D_NT1X_=100 /DWINNT=1 /D_WIN32_WINNT=0x0601 /DWINVER=0x0601 /D_WIN32_IE=0x0800    /DWIN32_LEAN_AND_MEAN=1  /DDEVL=1 /D__BUILDMACHINE__=WinDDK /DFPO=0  /DNDEBUG /D_DLL=1 /DNDEBUG   -DNDIS_WDM=1 -DNDIS51=1 /DNTDDI_VERSION=0x06010000   /Ic:\micon\myndis\sys\objfre_win7_x86\i386 /IC:\WinDDK\7600.16385.1\inc\api /IC:\WinDDK\7600.16385.1\inc\api /IC:\WinDDK\7600.16385.1\inc\ddk /IC:\WinDDK\7600.16385.1\inc\ddk /IC:\WinDDK\7600.16385.1\inc\crt .\ndisprot.rc
    1>Microsoft (R) Windows (R) Resource Compiler Version 6.1.6908.0
    1>Copyright (C) Microsoft Corporation.  All rights reserved.
    1> C:\WinDDK\7600.16385.1\Bin\x86\oacr\oacrcl @c:\micon\myndis\sys\objfre_win7_x86\i386\cl.rsp
    1>Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.207 for 80x86
    1>Copyright (C) Microsoft Corporation.  All rights reserved.
    1>cl /Fo"c:\micon\myndis\sys\objfre_win7_x86\i386/"
    1> /FC
    1> /Ii386
    1> /I.
    1> /Ic:\micon\myndis\sys\objfre_win7_x86\i386
    1> /IC:\WinDDK\7600.16385.1\inc\api
    1> /IC:\WinDDK\7600.16385.1\inc\api
    1> /IC:\WinDDK\7600.16385.1\inc\ddk
    1> /IC:\WinDDK\7600.16385.1\inc\ddk
    1> /IC:\WinDDK\7600.16385.1\inc\crt
    1> /D_X86_=1
    1> /Di386=1
    1> /DSTD_CALL
    1> /DCONDITION_HANDLING=1
    1> /DNT_UP=1
    1> /DNT_INST=0
    1> /DWIN32=100
    1> /D_NT1X_=100
    1> /DWINNT=1
    1> /D_WIN32_WINNT=0x0601
    1> /DWINVER=0x0601
    1> /D_WIN32_IE=0x0800
    1> /DWIN32_LEAN_AND_MEAN=1
    1> /DDEVL=1
    1> /D__BUILDMACHINE__=WinDDK
    1> /DFPO=0
    1> /DNDEBUG
    1> /D_DLL=1
    1> /DNDEBUG
    1> -DNDIS_WDM=1
    1> -DNDIS51=1
    1> /DNTDDI_VERSION=0x06010000
    1> /c
    1> /Zc:wchar_t-
    1> /Zl
    1> /Zp8
    1> /Gy
    1> /Gm-
    1> -cbstring
    1> /WX
    1> /W4
    1> /WX
    1> /Gz
    1> /hotpatch
    1> /EHs-c-
    1> /GR-
    1> /GF
    1> /GS
    1> /Zi
    1> /Oxs
    1> /Oy-
    1> /Zi
    1> /Fdc:\micon\myndis\sys\objfre_win7_x86\i386\
    1> /DKMDF_MAJOR_VERSION_STRING=01
    1> /DKMDF_MINOR_VERSION_STRING=009
    1> /wd4603
    1> /wd4627
    1> /typedil-
    1> /FIC:\WinDDK\7600.16385.1\inc\api\warning.h
    1> /Yuprecomp.h
    1> /Fpc:\micon\myndis\sys\objfre_win7_x86\i386\precomp.pch
    1> .\ntdisp.c .\ndisbind.c .\recv.c .\send.c .\debug.c .\registry.c .\excallbk.c 
    1>ntdisp.c
    1>ndisbind.c
    1>recv.c
    1>send.c
    1>debug.c
    1>registry.c
    1>excallbk.c
    1>Generating Code...
    1> C:\WinDDK\7600.16385.1\Bin\x86\oacr\oacrlink /out:c:\micon\myndis\sys\objfre_win7_x86\i386\ndisprot.sys /machine:ix86 @c:\micon\myndis\sys\objfre_win7_x86\i386\lnk.rsp
    1>Microsoft (R) Incremental Linker Version 9.00.30729.207
    1>Copyright (C) Microsoft Corporation.  All rights reserved.
    1>/MERGE:_PAGE=PAGE 
    1>/MERGE:_TEXT=.text 
    1>/SECTION:INIT,d 
    1>/OPT:REF 
    1>/OPT:ICF 
    1>/IGNORE:4198,4010,4037,4039,4065,4070,4078,4087,4089,4221 
    1>/INCREMENTAL:NO 
    1>/release 
    1>/NODEFAULTLIB 
    1>/WX 
    1>/debug 
    1>/debugtype:cv,fixup,pdata 
    1>/version:6.1 
    1>/osversion:6.1 
    1>/functionpadmin:5 
    1>/safeseh 
    1>/pdbcompress 
    1>/STACK:0x40000,0x1000 
    1>/driver 
    1>/base:0x10000 
    1>/subsystem:native,6.01 
    1>/entry:GsDriverEntry@8 
    1>/out:c:\micon\myndis\sys\objfre_win7_x86\i386\ndisprot.sys 
    1>c:\micon\myndis\sys\objfre_win7_x86\i386\precomp.obj 
    1>c:\micon\myndis\sys\objfre_win7_x86\i386\ndisprot.res 
    1>c:\micon\myndis\sys\objfre_win7_x86\i386\ntdisp.obj 
    1>c:\micon\myndis\sys\objfre_win7_x86\i386\ndisbind.obj 
    1>c:\micon\myndis\sys\objfre_win7_x86\i386\recv.obj 
    1>c:\micon\myndis\sys\objfre_win7_x86\i386\send.obj 
    1>c:\micon\myndis\sys\objfre_win7_x86\i386\debug.obj 
    1>c:\micon\myndis\sys\objfre_win7_x86\i386\registry.obj 
    1>c:\micon\myndis\sys\objfre_win7_x86\i386\excallbk.obj 
    1>C:\WinDDK\7600.16385.1\lib\win7\i386\BufferOverflowK.lib 
    1>C:\WinDDK\7600.16385.1\lib\win7\i386\ntoskrnl.lib 
    1>C:\WinDDK\7600.16385.1\lib\win7\i386\hal.lib 
    1>C:\WinDDK\7600.16385.1\lib\win7\i386\wmilib.lib 
    1>C:\WinDDK\7600.16385.1\lib\win7\i386\ndis.lib 
    1>C:\WinDDK\7600.16385.1\lib\win7\i386\wdmsec.lib 
    1>registry.obj : error LNK2019: unresolved external symbol __imp__fwrite referenced in function _CheckForAuthFile@0
    1>errors in directory c:\micon\myndis\sys
    1>c:\micon\myndis\sys\registry.obj : error LNK2019: unresolved external symbol __imp__fwrite referenced in function _CheckForAuthFile@0
    1>registry.obj : error LNK2019: unresolved external symbol __imp__fclose referenced in function _CheckForAuthFile@0
    1>c:\micon\myndis\sys\registry.obj : error LNK2019: unresolved external symbol __imp__fclose referenced in function _CheckForAuthFile@0
    1>registry.obj : error LNK2019: unresolved external symbol __imp__fread referenced in function _CheckForAuthFile@0
    1>c:\micon\myndis\sys\registry.obj : error LNK2019: unresolved external symbol __imp__fread referenced in function _CheckForAuthFile@0
    1>registry.obj : error LNK2019: unresolved external symbol __imp__fopen referenced in function _CheckForAuthFile@0
    1>c:\micon\myndis\sys\registry.obj : error LNK2019: unresolved external symbol __imp__fopen referenced in function _CheckForAuthFile@0
    1>c:\micon\myndis\sys\objfre_win7_x86\i386\ndisprot.sys : fatal error LNK1120: 4 unresolved externals
    1>c:\micon\myndis\sys\objfre_win7_x86\i386\ndisprot.sys : error LNK1120: 4 unresolved externals

    Monday, June 9, 2014 10:01 PM

Answers

  • The C runtimes you are using are user space only.  The USE_LIBCMT macro is for a user space program or DLL being created under BUILD.  You can use ZwCreateFile, ZwWriteFile and ZwClose to write a file.  But before you do this, why do you think you need to write a file in the first place?  Typically, drivers store their data in the registry not in a file.  If you are logging data, consider WPP tracing rather than file I/O.   Give us a clue of what you want to do at a high level, and we can probably suggest the best approach.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Monday, June 9, 2014 10:14 PM

All replies

  • The C runtimes you are using are user space only.  The USE_LIBCMT macro is for a user space program or DLL being created under BUILD.  You can use ZwCreateFile, ZwWriteFile and ZwClose to write a file.  But before you do this, why do you think you need to write a file in the first place?  Typically, drivers store their data in the registry not in a file.  If you are logging data, consider WPP tracing rather than file I/O.   Give us a clue of what you want to do at a high level, and we can probably suggest the best approach.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Monday, June 9, 2014 10:14 PM
  • Don:

    I am using the file minimally; only when the driver gets loaded to store just about 50 bytes of data in a file. The user needs to have easy access to this file and hence the use of File I/O. Did not see a down side to using files for his case. Are there some? Thanks.

    Br,

    -K

    Monday, June 9, 2014 10:52 PM
  • The biggest challenge of a file from a driver is where are you going to put it.  You might consider doing something like using a REG_BINARY value, and then creating a simple property page provider for the driver to read the data.


    Don Burn Windows Filesystem and Driver Consulting Website: http://www.windrvr.com Blog: http://msmvps.com/blogs/WinDrvr

    Monday, June 9, 2014 11:22 PM
  • Event logging?
    Tuesday, June 10, 2014 6:20 PM