unresolved external symbol __RTC_CheckEsp and others
-
2006年9月13日 17:24Hello,
I am trying to complile and link a bunch of code which makes use of the setupapi.h and hdisdi.h, defined as "extern C". I need the Win DDK, which are correctly installed together with Visual C++ 2005 Express Edition. I am underlining those includes because they caused many link errors. Only after reading previous answers, I reduced their number but am not able to fix the last 3 :-(
The linker errors I still get are:
DisplayUSB.obj : error LNK2019: unresolved external symbol __RTC_CheckEsp referenced in function _main
DisplayUSB.obj : error LNK2001: unresolved external symbol __RTC_Shutdown
DisplayUSB.obj : error LNK2001: unresolved external symbol __RTC_InitBase
.\Debug/DisplayUSB.exe : fatal error LNK1120: 3 unresolved externals
Can anybody suggest how to fix this problem ?
Thanks in advance !
Marco
P.S. for experts more than myself, the complete log follows obtained by means of the /VERBOSE option:
------ Rebuild All started: Project: DisplayUSB, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'DisplayUSB', configuration 'Debug|Win32'
Compiling...
StdAfx.cpp
Compiling...
DisplayUSB.cpp
Compiling manifest to resources...
Linking...
Starting pass 1
Searching libraries
Searching F:\WINDDK\3790.1830\lib\wxp\i386\odbc32.lib:
Searching F:\WINDDK\3790.1830\lib\wxp\i386\odbccp32.lib:
Searching F:\WINDDK\3790.1830\lib\crt\i386\msvcrt.lib:
Found _printf
Referenced in DisplayUSB.obj
Loaded msvcrt.lib(msvcrt.dll)
Found _mainCRTStartup
Loaded msvcrt.lib(crtexe.obj)
Found __IMPORT_DESCRIPTOR_msvcrt
Referenced in msvcrt.lib(msvcrt.dll)
Loaded msvcrt.lib(msvcrt.dll)
Found __imp___c_exit
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(msvcrt.dll)
Found __imp___exit
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(msvcrt.dll)
Found __XcptFilter
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(msvcrt.dll)
Found __imp___cexit
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(msvcrt.dll)
Found __imp__exit
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(msvcrt.dll)
Found __imp____initenv
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(msvcrt.dll)
Found ___xc_a
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(cinitexe.obj)
Found __imp____getmainargs
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(msvcrt.dll)
Found __dowildcard
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(wildcard.obj)
Found __newmode
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(_newmode.obj)
Found __initterm
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(msvcrt.dll)
Found __setdefaultprecision
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(fp8.obj)
Found __imp____setusermatherr
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(msvcrt.dll)
Found __matherr
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(merr.obj)
Found __setargv
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(dllargv.obj)
Found __adjust_fdiv
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(adjustfd.obj)
Found __imp___adjust_fdiv
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(msvcrt.dll)
Found __commode
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(ncommode.obj)
Found __imp____p__commode
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(msvcrt.dll)
Found __fmode
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(txtmode.obj)
Found __imp____p__fmode
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(msvcrt.dll)
Found ___onexitbegin
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(atonexit.obj)
Found __imp____set_app_type
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(msvcrt.dll)
Found __SEH_epilog
Referenced in msvcrt.lib(crtexe.obj)
Loaded msvcrt.lib(sehprolg.obj)
Found __except_handler3
Referenced in msvcrt.lib(crtexe.obj)
Referenced in msvcrt.lib(sehprolg.obj)
Loaded msvcrt.lib(msvcrt.dll)
Found __NULL_IMPORT_DESCRIPTOR
Referenced in msvcrt.lib(msvcrt.dll)
Loaded msvcrt.lib(msvcrt.dll)
Found msvcrt_NULL_THUNK_DATA
Referenced in msvcrt.lib(msvcrt.dll)
Loaded msvcrt.lib(msvcrt.dll)
Found __controlfp
Referenced in msvcrt.lib(fp8.obj)
Loaded msvcrt.lib(msvcrt.dll)
Found ___dllonexit
Referenced in msvcrt.lib(atonexit.obj)
Loaded msvcrt.lib(msvcrt.dll)
Found __imp___onexit
Referenced in msvcrt.lib(atonexit.obj)
Loaded msvcrt.lib(msvcrt.dll)
Searching F:\WINDDK\3790.1830\lib\wxp\i386\kernel32.lib:
Searching F:\WINDDK\3790.1830\lib\wxp\i386\odbc32.lib:
Searching F:\WINDDK\3790.1830\lib\wxp\i386\odbccp32.lib:
Finished searching libraries
Finished pass 1
Generating non-SAFESEH image.
Invoking CVTRES.EXE:
/machine:x86
/verbose
/out:"C:\DOCUME~1\marco\IMPOST~1\Temp\lnk205.tmp"
/readonly
".\Debug\DisplayUSB.exe.embed.manifest.res"
Microsoft (R) Windows Resource To Object Converter Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.
adding resource. type:MANIFEST, name:1, language:0x0409, flags:0x30, size:2048
DisplayUSB.obj : error LNK2019: unresolved external symbol __RTC_CheckEsp referenced in function _main
DisplayUSB.obj : error LNK2001: unresolved external symbol __RTC_Shutdown
DisplayUSB.obj : error LNK2001: unresolved external symbol __RTC_InitBase
.\Debug/DisplayUSB.exe : fatal error LNK1120: 3 unresolved externals
Build log was saved at "file://f:\ElbaTech Software\USB\USB Microcontroller\MyDisplay USB\Debug\BuildLog.htm"
DisplayUSB - 4 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
答案
-
2006年9月13日 19:47版主
VC8 (or VS2005) assumes the use of VC8 libraries, which contain certain functions needed by the compiler. msvcrt.lib doesn't carry these.
I personally don't know the recommended dev environment for doing device drivers using VC8.
If these symbols are the only problem, then you can disable their use by turning off Basic Runtime Checks (disable /RTC) and Buffer Security Checks (/GS-). These settings are under C/C++ code generation. But other dependencies may creep up on you that are not covered by these flags.
Failing this, try to use the CRT that comes with VC8.
Brian
全部回复
-
2006年9月13日 19:47版主
VC8 (or VS2005) assumes the use of VC8 libraries, which contain certain functions needed by the compiler. msvcrt.lib doesn't carry these.
I personally don't know the recommended dev environment for doing device drivers using VC8.
If these symbols are the only problem, then you can disable their use by turning off Basic Runtime Checks (disable /RTC) and Buffer Security Checks (/GS-). These settings are under C/C++ code generation. But other dependencies may creep up on you that are not covered by these flags.
Failing this, try to use the CRT that comes with VC8.
Brian
-
2006年9月14日 20:14Ok, I took a little time to check on this. The use of the CRT/Compiler that does not come with the DDK is possible but not supported. If I was you, write it in the IDE for ease of use, but when you are doing your compilation, use the DDK compiler environment. It would be easier that way.
-
2006年9月14日 20:29
Many thanks for your help. As you have noticed, once some errors are fixed, others appear.
I list in the following the source code, in the hope that you or somebody else can tell me what options to set exactly in Visual C++ Express Edition to see it compiled and linked.
Many thanks in advance !
Marco
Here is the code:
#include "stdafx.h"
#include "objbase.h"
#include <iostream>
extern "C" {
// Declare the C libraries used
#include "setupapi.h"
#include "hidsdi.h"
}
HANDLE Handle;
bool OpenUSBinterface() {
struct _GUID GUID;
SP_INTERFACE_DEVICE_DATA DeviceInterfaceData;
struct {DWORD cbSize; char DevicePath[256];} FunctionClassDeviceData;
int Device, i;
HANDLE PnPHandle;
char buffer[256];
unsigned long BytesReturned;
bool Success, Openned;
const char *DeviceName = "Buttons & Lights";
SECURITY_ATTRIBUTES SecurityAttributes;
// Initialize the GUID array and setup the security attributes for Win2000
HidD_GetHidGuid(&GUID);
SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
SecurityAttributes.lpSecurityDescriptor = NULL;
SecurityAttributes.bInheritHandle = false;
// Get a handle for the Plug and Play node and request currently active devices
PnPHandle = SetupDiGetClassDevs(&GUID, NULL, NULL, DIGCF_PRESENT|DIGCF_INTERFACEDEVICE);
if (int(PnPHandle) == -1) { printf("Could not attach to PnP node"); return false; }
// Lets look for a maximum of 20 Devices
Openned = false;
Handle = INVALID_HANDLE_VALUE;
for (Device = 0; (Device < 20); Device++) {
// Initialize our data
DeviceInterfaceData.cbSize = sizeof(DeviceInterfaceData);
// Is there a device at this table entry
Success = SetupDiEnumDeviceInterfaces(PnPHandle, NULL, &GUID, Device, &DeviceInterfaceData);
if (Success) {
// There is a device here, get it's name
FunctionClassDeviceData.cbSize = 5;
Success = SetupDiGetDeviceInterfaceDetail(PnPHandle, &DeviceInterfaceData,
(PSP_INTERFACE_DEVICE_DETAIL_DATA)&FunctionClassDeviceData, 256, &BytesReturned, NULL);
if (!Success) { printf("Could not find the system name for this Device\n"); return false; }
// Can now open this Device
Handle = CreateFile(FunctionClassDeviceData.DevicePath, GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, &SecurityAttributes, OPEN_EXISTING, 0, NULL);
if (Handle == INVALID_HANDLE_VALUE) printf("Could not open HID device\n");
else {
// Is it OUR Device?
HidD_GetProductString(Handle, buffer, sizeof(buffer));
// Compare incoming string with UNICODE string
Openned = true; i = 0;
while (DeviceName
!= 0) { if (buffer[2*i] != DeviceName
) {Openned =
false;} i++;}
if (Openned) break;
}
} // if (SetupDiEnumDeviceInterfaces . .
} // for (Device = 0; (Device < 20); Device++)
SetupDiDestroyDeviceInfoList(PnPHandle);
return Openned;
}
int main(int argc, char* argv[]) {
char InputCharacter;
int Choice, LEDvalue, i;
unsigned long BytesWritten, BytesRead;
UCHAR ReplyBuffer[2];
UCHAR LightsCommand[2] = {0, 0};
// Say Hello to the user
printf("\nVisual C++ version of 'Buttons and Lights'\n\n");
// Search for and open our HID device
if (!OpenUSBinterface()) {
printf("Buttons and Lights device was not found\n");
cin >> InputCharacter;
return -1;
}
// A simple, prompted interface. Needs improvement!!
do {
printf("\nThe following commands are available:\n");
printf("B = Read the device 'Buttons'\n");
printf("L = Set the device 'Lights'\n");
printf("E = Exit this program\n");
printf("Please enter your choice: ");
cin >> InputCharacter;
Choice = InputCharacter;
switch (tolower(Choice)) {
case 'b':
if (!ReadFile(Handle, ReplyBuffer, sizeof(ReplyBuffer), &BytesRead, NULL))
printf("Error reading from HID device\n");
printf("\nButtons value = ");
for (i=0; i<8; i++) printf("%s", ((ReplyBuffer[1] >> i) & 1) ? "0" : "1");
printf("\n");
break;
case 'l':
printf("\nValue to be written to Lights: ");
cin >> LEDvalue;
LightsCommand[1] = LEDvalue;
if (!WriteFile(Handle, LightsCommand, sizeof(LightsCommand), &BytesWritten, NULL))
printf("Error writing Command to I/O device\n");
break;
case 'e':
printf("\n\n");
CloseHandle(Handle);
return 0;
default: printf("\nInvalid Selection\n"); break;
}
} while (1);
} // Main -
2006年9月14日 20:32版主I can't compile this because it needs hdisdi.h. How about if you just give us the lines of code that produce errors, along the errors. Then we can give general guidelines on how to fix them.
-
2006年9月14日 22:25
I'll give you what I found, but all I can say is don't do it.
There are always problems linking one version of the CRT against a version of a compiler that it wasn't written for.
C/C++ settings for VC2005
General
Additional Include Directories:
C:\WINDDK\2600\inc\wxp
C:\WINDDK\2600\inc\ddk\wxp
C:\WINDDK\2600\inc\ddk\wdm\wxp
C:\WINDDK\2600\inc\crt
Preprocessor
Preprocessor Definitions:
X86_=1
i386=1
_WIN32_WINNT=0x0501
WINVER=0x0501
WIN32_LEAN_AND_MEAN=1 ... dont know if this does much for a device driver
Ignore Standard Include Path:Yes (/X)
Code Generation
Enable C++ Exceptions:No ... no exception handling in the kernel!
Buffer Security Check:No (/GS-) ... linker error if set to Yes
Language
Enable Run-Time Type Info:No (/GR-) ... linker error if set to YesLinker settings for VC2005
Input
Additional Dependencies:int64.lib ntoskrnl.lib hal.lib ... etc.
Ignore All Default Libraries:Yes (/NODEFAULTLIB)
Manifest File
Generate Manifest:No
System
SubSystem:Native (/SUBSYSTEM:NATIVE)
Driver:Driver (/DRIVER)
Advanced
Base address:0x10000
Entry Point:DriverEntry
Target Machine:MachineX86 (/MACHINE:X86)General
Additional Library Directories:C:\WINDDK\2600\lib\wxp\i386
You change the paths to your paths obviously, but this is what the original poster said worked. -
2006年9月15日 13:45
Many many thanks for your attention and help!
Finally I succeded compiling and linking the above posted code with slightly different compiler/linker options, which I report for a sake of clarity at the bottom of this message.
When I tried to run the application, however, a runtime error occurred stating that msvcp60d.dll was missing.
Throughout other posts of this forum I discovered that I need to build a release version of the project, since the requested DLL is build-dependent and cannot be copied from other sites.
I tried to compile the code as "release" instead of "debug", after putting the very same compiler and linker options in the respective places.
Unfortunately the code is no longer linked, with the following errors:
prova.cpp
.\prova.cpp(37) : warning C4311: '<function-style-cast>' : pointer truncation from 'HANDLE' to 'int'
.\prova.cpp(48) : warning C4800: 'BOOL' : forcing value to bool 'true' or 'false' (performance warning)
.\prova.cpp(54) : warning C4800: 'BOOL' : forcing value to bool 'true' or 'false' (performance warning)
Compiling manifest to resources...
Linking...
LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/LTCG' specification
prova.obj : error LNK2001: unresolved external symbol _atexit
prova.obj : error LNK2001: unresolved external symbol "public: __thiscall std::ios_base::Init::Init(void)" (??0Init@ios_base@std@@QAE@XZ)
prova.obj : error LNK2001: unresolved external symbol "public: __thiscall std::ios_base::Init::~Init(void)" (??1Init@ios_base@std@@QAE@XZ)
prova.obj : error LNK2001: unresolved external symbol "public: __thiscall std::_Winit::_Winit(void)" (??0_Winit@std@@QAE@XZ)
prova.obj : error LNK2001: unresolved external symbol "public: __thiscall std::_Winit::~_Winit(void)" (??1_Winit@std@@QAE@XZ)
prova.obj : error LNK2001: unresolved external symbol _printf
LINK : error LNK2001: unresolved external symbol _wmainCRTStartup
What is wrong now ?
Thanks again,
Marco
P.S. here are the compiler and linker options which have success with the debug version:
Compiler:
/Od /I "F:\WINDDK\3790.1830\inc\crt" /I "F:\WINDDK\3790.1830\inc\wxp" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /MDd /GS- /Yu"stdafx.h" /Fp"Debug\prova.pch" /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /nologo /c /Wp64 /ZI /TP /errorReport:prompt
Linker:
/OUT:"F:\ElbaTech Software\USB\USB Microcontroller\MyButttonsAndLights\prova\Debug\prova.exe" /INCREMENTAL /NOLOGO /LIBPATH:"F:\WINDDK\3790.1830\lib\crt\i386" /LIBPATH:"F:\WINDDK\3790.1830\lib\wxp\i386" /MANIFEST /MANIFESTFILE:"Debug\prova.exe.intermediate.manifest" /DEBUG /PDB:"f:\ElbaTech Software\USB\USB Microcontroller\MyButttonsAndLights\prova\debug\prova.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 /ERRORREPORT:PROMPT kernel32.lib setupapi.lib hid.lib
-
2007年4月18日 12:11
Don't use the VC compiler to compile drivers. The best approach if you want to use the DDK together with Visual Studio is to use DDKBUILD in one of the available flavors. There is one from OSR and one from Hollistech. At OSR you find a .bat and a .cmd version. The latter one is currently maintained by me.
If you need some help setting up the DDK project(s), DDKWizard might be the solution for your problems: http://ddkwizard.assarbad.net
Note that the DDKWizard manual describes how to configure and set up DDKBUILD and DDKWizard, so even though you may not want to use the wizard, you may find the information in the manual valuable when configuring your system for use of DDKBUILD.
Best regards,
Oliver
PS: There is even one advantage when using the DDK to build console or GUI (i.e. usermode) applications. The headers are updated to be compliant with the new compiler (which is not equal but apparently similar to the one in VS/VC) to allow you to link against the old msvcrt.lib and so on. I.e. you can more easily migrate old MFC projects or old Visual C++ projects by using the DDK. This means there is no need to distribute the respective libraries of newer CRT or MFC versions ;-)
-
2007年8月18日 9:07
Peharps you solved your problems, or not. Don't use the .lib of DDK to link. Prefer the VC8's. Your lib exists in the VC8 lib directory. It has worked for me.
Jonjon
-
2011年7月22日 16:02
I just today ran into this problem with some projects that we inherited. The problem was that the Linker->Input->Ignore Specific Default Libraries setting was specifically ignoring lots of libraries, including CRT and other Microsoft libraries. I have no idea why those were set, but like I said, we only inherited these projects from someone else.
Solution:
So I just erased those entries and it all the linker errors were all cleared up.

