Unresolved external symbol - c++

Help me guys,
I've been searching for a really long time.
I'm using visual studio 2010 and I tried to include an external lib but I get an unresolved external error.
The external project is composed of files in the following way
backend.cpp
//some functions
frontend.cpp
//some functions
header.h
I build this project using SCons then I includes the .lib file in the project and refered to its path and I copied the .h file to msvc directory .
VS seems to access and read the functions in backend.cpp(from the auto complete) but when I run the project it says that there is an unresolved external # the called function

I'm not a Visual Studio expert, but I guess that it being able to auto complete your code is associated with it finding the headers of your source code.
Unresolved external means that the compiler can't find the object files in the linking process. This could mean that you failed to add the lib files correctly, or that you are missing some .cpp file.

That may happen for a variety of reasons. But all of them end up being one of the following:
You are not linking the correct .lib file.
The symbol name you are using in your program is not identical to the one provided in the .lib.
The first one is easy enough to check, so please, double check it.
The second one is trickier. The symbol name used in your program is output in the error message "unresolved external symbol abc", or whatever. The symbols available in the library can be listed with the command: dumpbin /all name.lib.
If you cannot find the problem, please post the exact error you are getting and the output of the dumpbin program.

Related

VS2015 Linking .dll/.so in C++

I have the following files (https://www.dropbox.com/s/2bfhylzb2evrggp/Lib.rar?dl=0)
It contains the header file, .so and .dll file.
I added the aditional paths under C/C++ and Linker (to the dll.s and .h files)
I have also used the sample code in the rar file and VS2015 picks up the code
include "swi32.h"
But as soon as I try to use a method defined in the headerfile I get the following
Severity Code Description Project File Line Suppression State
Error LNK1120 1 unresolved externals ConsoleApplication1 C:\Users\Donald Jansen\Desktop\CPPTest\Swi32Test\ConsoleApplication1\Debug\ConsoleApplication1.exe 1
Error LNK2019 unresolved external symbol _WiCreateRawImage#0 referenced in function _main ConsoleApplication1 C:\Users\Donald Jansen\Desktop\CPPTest\Swi32Test\ConsoleApplication1\Console.obj 1
I am not sure what I am missing
If you are implicitly linking the dll, then you must have also received a .lib file which you need to link with your console application. This should remove the unresolved symbol warning. The operating system loads the DLL when the executable using it is loaded.
If you are explicitly linking the dll, then your code should explictly load and unload the DLL to access the exported functions.
The .so you mention probably is a linux shared object file and not useful on windows platform. I may be wrong though.

Link against a 3rd-party library with Visual Studio

I'm trying to create a .dll with Visual Studios 2013. The project includes libpq functionality.
Per other stackoverflow posts, and other sources I've found on the internet, I've (as far as I'm aware) correctly added the postgres lib and include directories to the project. However, when I go to build the project, it returns a number of "unresolved external symbol" errors.
My paths are C:\Program Files\PostresSQL\9.3\... so I have them surrounded by quotation marks in the Additional Library/Include Directory fields. I've included the libpq-fe.h header file in the project... I'm just not sure what I'm doing wrong.
Another note, I can compile a test program from the command line using g++ with the -I, -L, and -lpq flags, but I'm not sure how to compile to a .dll from the command line (plus it adds complexity that I just don't want to deal with).
These are the specific errors I'm getting:
1>sql_arma.obj : error LNK2001: unresolved external symbol _PQconnectdb
1>sql_arma.obj : error LNK2001: unresolved external symbol _PQstatus
1>sql_arma.obj : error LNK2001: unresolved external symbol _PQerrorMessage
1>sql_arma.obj : error LNK2001: unresolved external symbol _PQfinish
1>C:\Users\tills13\documents\visual studio 2013\Projects\sql_arma\Release\sql_arma.dll : fatal error LNK1120: 4 unresolved externals
I have, as suggested below, included #pragma comment(lib, "libpq.lib") in the source file for my project, I still receive these errors.
I've successfully compiled the sample program by setting these project properties:
Add <pgsql install path>\include and \lib to VC++ Directories->Include and ->Library, correspondingly
Add libpq.lib to Linker->Input->Additional dependencies
This is the standard way to reference 3rd-party libs. It's just that they recommend using environment variables for their "base dirs" to avoid patching the project when it's under a VCS.
To be able to run the app from VS (both with and without debugging), I also specified PATH=%PATH%;<pgsql install path>\bin in Debugging->Environment since this dir isn't in PATH on my system.
It's not sufficient add the postgres lib directory to the project, you must also add
reference to libpq.lib. Just add this line to one of your source .cpp files:
#pragma comment(lib, "libpq.lib")
As noted by Marco A. the library must match a program bitness (32 or 64 bit): if you build 32-bit DLL (referred as Win32) you must use 32 bit library; if 64-bit (x64) - 64-bit library.
I have also faced same issue. Then I realized that I was building my application as a 32bit. I changed the target of my application to x64 and it compiled successfully

Linker error while linking some windows APIs

I have a makefile project in my system. Recently, I added some new functions which makes use of the following Windows APIs:
RegOpenKeyEx
RegEnumKeyEx
RegCloseKey
RegGetValue
For having those APIS I added the windows.h header file as well.
The code compiles and links fine in my machine. But, linking fails in my colleagues machine. We all are working on 64 bit windows machine.
In his PC I get the error:
error LNK2001: unresolved external symbol __imp_RegOpenKeyExW
error LNK2001: unresolved external symbol __imp_RegGetValueW
error LNK2001: unresolved external symbol __imp_RegCloseKey
error LNK2001: unresolved external symbol __imp_RegEnumKeyExW
What I tried:
Since the library being used was Advapi32.lib in C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Lib\x64
I tried adding following line:
LINKFLAGS += -L "C:\Program Files (x86)\Microsoft
SDKs\Windows\v7.0A\Lib\x64"
I added the path of the library to environment variable PATH
I copied the lib to the output folder.
Nothing worked.
As I said earlier, the code works fine in my PC but fails in another one.
The registry functions require you to pass Advapi32.lib to the linker. This is the step that you have missed.
If you are using visual stdio, check your project property vs your friend's project property and check link library path+ library name with .lib shoul be included. It seems in your friends computer is not getting the library to resolve the symbols. Compile time checking is done only with header files. While linking it should find the definition of yor function in library.
for command line:
from:http://social.msdn.microsoft.com/Forums/vstudio/en-US/6bcae3d1-85b6-471d-a4ee-7b455b21460b/how-do-i-link-libraries-that-are-sitting-in-different-directories-from-the-command-line?forum=vcgeneral
cl main.obj ab1.lib ab2.lib de1.lib de2.lib gh1.lib /Fetestmain.exe /link /LIBPATH:C:\test\ab /LIBPATH:C:\test\de /LIBPATH:C:\test\gh
The "/link" is very important...do not use "/LINK", the uppercase LINK is not recognised.

unresolved external symbol compile error

I frequently have this problem when I try a new library. This time I work with PointGrey Camera and try to use its API libraries (some dll, lib, header files). Mostly, problems were fixed by configuring the SDK (I'm using VS2008) Tools/Options/VC++ Directories/include files(/library files)(/executable files),
I also tried with project configuration:
+ project properties/linker/input/additional dependencies
+ project properties/linker/General/Additional Library Directories
This time, with all this, I still have the error.
Is there a general method to deal with this problem?
do I need to understand this diagnosis from VS2008?
Error 1 error LNK2019: unresolved external symbol __imp__flycaptureGetPacketInfo referenced in function "enum FlyCaptureError __cdecl initializeStandardEventSizes(void *,struct FlyCaptureImageEvent * const)" (?initializeStandardEventSizes##YA?AW4FlyCaptureError##PAXQAUFlyCaptureImageEvent###Z) main_2.obj test
does using analysis tool such as Dependencies Walker ensure to solve these problems well??
This message says that you used a symbol (a function or a variable) in your code. This symbol was probably declared somewhere (most likely in a header file you included in your code) otherwise there would have been a compilation error. When the linker searched for the symbol (in both your object files and the lib files you instructed it to look in) it couldn't find it.
That usually happens because you forgot to let the linker know about a lib you want it to search in.
Most libraries come with a set of instruction that is supposed to help you set up everything correctly and avoid running into these problems.
This problem has been solved lately. I installed the incompatible library of PointGrey. That's why it didn't work. But this says something between "incompatible library" and "unresolved exertal symbol error"

Debugging Visual Studio linker

I am trying to build an xll addin for Excel using appropriate framwork downloaded from MS website. I am getting the following linker errors:
1>FRAMEWRK.obj : error LNK2001: unresolved external symbol _Excel4
1>FRAMEWRK.obj : error LNK2001: unresolved external symbol _Excel4v#16
I think that these should be defined in XLCALL32.LIB included in the package from MS, but I don't know how to check it. Moreover, added the folder containing this library to the Additional Library Directories, without luck.
Hence my questions:
(1) How can I check what is in XLCALL32.LIB?
(2) How can I see which files the linker is using to see if my library is actually included?
In your project properties, Under Configuration Properties->Linker->Input, you will see 'Additional Dependencies' - these are the files the linker is using. Assuming that _Excel4 and _Excel4v are defined in XLCALL32.LIB (which I think they are), you simply need to ensure that this file is specified in this list.