I am using C++Builder XE2. In my project I use a mix of C++ and Delphi components, which so far has worked great.
I use one particular Delphi component - TATViewer, which is an image viewer. The Delphi files are included in a C++Builder .cbproj project and compile and install just fine.
The component can be extended with JPEG 2000 support by using JasPer JPEG 2000 library, which is written in C, but has a fine Delphi wrapper (http://sourceforge.net/projects/pasjas/). The Delphi wrapper is a single Delphi unit that links in the C .obj files.
Everything compiles, but during linking I run into problems: It cannot find the C library functions used by the JasPer library:
[ILINK32 Error] Error: Unresolved external 'strchr' referenced from C:\COMPONENTS\BCBXE2\ATVIEWER\CBUILDER\JP2IMG.OBJ
[ILINK32 Error] Error: Unresolved external 'atol' referenced from C:\COMPONENTS\BCBXE2\ATVIEWER\CBUILDER\JP2IMG.OBJ
[ILINK32 Error] Error: Unresolved external 'wcscpy' referenced from C:\COMPONENTS\BCBXE2\ATVIEWER\CBUILDER\JP2IMG.OBJ
[ILINK32 Error] Error: Unresolved external 'abort' referenced from C:\COMPONENTS\BCBXE2\ATVIEWER\CBUILDER\JP2IMG.OBJ
The Delphi unit uses the crtl library which is a wrapper around most C libraries, and declares the functions not included in crtl itself:
const
msvcrtdll = 'msvcrt.dll';
//referenced functions, not declared in delphi crtl unit
procedure __assert; external msvcrtdll name '_assert';
procedure _atexit; external msvcrtdll name 'atexit';
procedure _abort; external msvcrtdll name 'abort';
procedure _strrchr; external msvcrtdll name 'strrchr';
How do I get this C++Builder project with Delphi units using C functions to link? I'm sure I must be missing something simple.
Related
I created a default ATL project with MSVC 2010 with a simple default ATL dialog. Then I added the second project into solution, named MyControls, where I created ATL DHTML Control with a help of Wizard. Then I placed ATL DHTML Control to ATL dialog.
Now I would like to call some methods of that ATL DHTML Control in ATL dialog's OnInitDialog function. In order to be able to make a call like:
CComPtr<IDHTMLControl> ptr;
HRESULT hr = GetDlgControl(IDC_ACTIVEX_CONTROL_DHTML
, IID_IDHTMLControl, (void**)&ptr);
I am including the file DHTMLControl.h from MyControls project. However, I get the following errors:
Error 1 error LNK2001: unresolved external symbol _IID_IDHTMLControl
Error 2 error LNK2001: unresolved external symbol _LIBID_MyControlsLib
Error 3 error LNK2001: unresolved external symbol _CLSID_DHTMLControl
Error 4 error LNK2001: unresolved external symbol _IID_IDHTMLControlUI
Note: It appears that I am linking MyControls.lib incorrectly, however, I added MyControls.lib to Linker->Input->Additonal Dependencies & specified ../$(Configuration) in the Linker->General->Additional Library Directories.
Anyone have an idea?
Thanks!
The problem is related to how you link one project with the other. There is something missing here and since you don't show the code, it's a pure guess only.
On control project you have a type library which, when being built, also generates files MyControls_i.h, MyControls_i.c, MyControls_p.c. I suppose that on the application project you included _i.h file which declared symbols as externals, and you did not include the _i.c file with symbols actually defined.
I'm trying to use an external DLL (provided by AutoItX) with Visual C++ 2010. AutoItX provides a DLL, but for some reason not a LIB, so I generated one with Visual Studio.
The problem is that the linker seems to have trouble linking against the library. I added AutoItX3.lib as an additional dependency under Properties->Linker -> Inputs, and added the directory to Properties -> Linker -> General -> Additional Library Directories. No matter what I do, I still get these errors:
1>main.obj : error LNK2019: unresolved external symbol _AU3_Send#8 referenced in function _WinMain#16
1>main.obj : error LNK2019: unresolved external symbol _AU3_WinWaitActive#12 referenced in function _WinMain#16
1>main.obj : error LNK2019: unresolved external symbol _AU3_Run#12 referenced in function _WinMain#16
1>main.obj : error LNK2019: unresolved external symbol _AU3_Sleep#4 referenced in function _WinMain#16
AU3_Send, AU3_WinWaitActive, AU3_Run, and AU3_Sleep are functions called by the program, main.cpp. I'm really out of ideas, because these functions clearly exist in the DLL. Any help would be appreciated.
It is very common to provide only DLLs as a mean of interfaces. Many software providers do that. Doing this has following impacts (consequences):
the client applications can only dynamically link to the library provided (hence the name Dynamic-Link Library). The binding between the provider (the library) and the consumer (the App or any other Library) is made dynamically.
the client must use LoadLibray and GetProcAddress in order to bind the library and retrieve the Symbols (functions) desired
the interface (contract) between the Library and the consumer should be documented via a Header file - see AutoIt3.h for example - (or any other documentation like a help file, ..)
No LIB is provided (since it is not needed), since the Linking takes place at runtime, not at compiler/linker time
To resolve your problem you just need to remove the static dependency (the LIB) you put in the Visual Studio configuration and set the dependency at runtime using LoadLibrary and GetProcAddress
Link errors like this sometimes occur when compiling C++ using Microsoft Visual C++ 6.0:
error LNK2001: unresolved external symbol __imp__close
error LNK2001: unresolved external symbol __imp__read
error LNK2001: unresolved external symbol __imp__lseek
error LNK2001: unresolved external symbol __imp__open
My fix, which I found after searching fruitlessly using Google for a long time, is this:
Do NOT disable language extensions. In the Project Settings dialog, in the C/C++ tab, make sure that the 'Disable language extensions' checkbox is not checked.
The functions close, read, lseek, open, etc., are not standard parts of the C library and the declarations are skipped by conditional compilation using #if !__STDC__ in <io.h>. This happens if you disable language extensions.
The answer is that the __imp prefix refers to function stubs in the OBJ library for the DLL version of the CRT. This means your linker options are incompatible with your compiler options (linker set to static CRT or no CRT and compiler set to dynamic CRT).
In your case rather than the CRT itself it is another library, but the same idea.
I created my own ODBC wrapper class which handles SQL from C++ Win32 application.
I have copied and Added (as existing) this class to my MFC application.
Now I have terrible linking problems with unresolved external symbols (which were NOT present in the Win32 perfectly working app), such as this: "
Error 56
error LNK2019: unresolved external symbol _SQLSetStmtAttr#16 referenced in function
"public: int __thiscall Cosql::ODBCconnect(char *)" (?ODBCconnect#Cosql##QAEHPAD#Z)
C:\Documents and Settings.........\Cosql.obj ApplicationName
"
How can I PROPERLY include "sqlext.h" (and "sql.h") from
C:\Program Files\Microsoft SDKs\Windows\v7.0A in my MFC application or MORE importantly: How to resolve those external symbols?
Am I the only one trying to ODBC-connect from a MFC app and having this trouble ??? :O
I Just know that "SQLSetStmtAttr" function is there defined only for ODBCVER 3.0 and higher. Well ! But HOW do I set ODBCVER in my MFC app. ??? I have no idea.
EDIT: I figured out that ODBCVER is defined: 0x0380 (so it is ver. 3.8),
all functions are defined correctly by those includes: sql.h and sqlext.h ,
EDIT II: Linking ERROR persists when I convert all those methods (object) into pure functions using some global variables!
Thanx in advance.
Solved.
Solution: I created a DLL from my ODBC class and then used it in my project.
Now it is compiled independently so it does not restrict each other's INCOMPATIBLE environment and compiler settings anymore!
I'm updating some legacy apps to Visual Studio 10 and am in linker hell. All of these DLLs derive classes from CWinApp and use AfxGetApp() to get access to the object. When I link the DLLs I get unresolved externals that look like global static objects that would get pulled in by a normal app's main():
Shell.lib(SHELL.obj) : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CException::classCException" (?classCException#CException##2UCRuntimeClass##B)
Shell.lib(SHELL.obj) : error LNK2001: unresolved external symbol "public: static struct CRuntimeClass const CFrameWnd::classCFrameWnd" (?classCFrameWnd#CFrameWnd##2UCRuntimeClass##B)
Shell.lib(SHELL.obj) : error LNK2001: unresolved external symbol "public: static class CRect const CFrameWnd::rectDefault" (?rectDefault#CFrameWnd##2VCRect##B)
My current combination of ignore default libraries and additional libraries (the method you can easily google to find the answer to linker hell) is: msvcprtd.lib,mfc100d.lib,mfcs100d.lib,libcmtd.lib
When I add nafxcwd.lib (the mfc library), these three external symbols resolve but I end up with a bunch of other duplicate symbols (requiring the use of /FORCE:MULTIPLE) and in end ___argc and ___argv become unresolved.
So the basic question is: Can you link a DLL containing a CWinApp in VS10? How do you setup the linker to do it?
Can you link a DLL containing a CWinApp in VS10?
When I create a new project in Visual Studio 10 and use the MFC DLL template, I found the template code itself includes a class derived from CWinApp. Of course the template compiles and links fine, so the answer to this question is a most definite yes.
I searched for definitions to those objects that your linker is complaining about and I found them in afx.h and afxwin.h, inside Visual Studio's include directory, packaged with the rest of the ATL and MFC code that is included with Visual Studio when you install it.
Are you using the express edition by chance? One of the few differences between the express edition and the pro edition of Visual Studio 2010 is that ATL and MFC applications won't compile in the express edition. You have to use the pro edition.