Unresolved external when trying to use .lib/.dll - c++

I am trying to add ANN(open source k-d tree for fast nearest neighbor searching) to my VC++ project. I followed the manual and completed every step:
include the .h files
copy the .lib file, add its location to the linker additional directory
copy the .dll file, set location to environmental variable PATH, and import it in my project
I still get 24 "unresolved external..." errors. The library seems to be widely used and not supposed to be wrong, wondering what else do I need to do to use it?
Thanks guys!

The "unresolved external" error comes because the linker is not finding the "lib" files. The DLL files are only found during run time, not link time.
Do you set the names of the lib files in the project's Properties?
Configuration Properties -> Linker -> Input -> Additional Dependencies
Enter the filenames of the all the lib files, separated by spaces. If they are in your Project folder, use something like
$(ProjectDir)Foobar.lib

have you set path of lib correctly?
you can use lib file along with its path in
on Configuration Properties -> Linker -> Input -> Additional Dependencies
or
just give lib file name in
Configuration Properties -> Linker -> Input -> Additional Dependencies
and lib path in
Configuration Properties -> Linker -> General -> Additional library directories

Related

How to link mysqlcppconn.lib to a c++ project

I'm trying to use the mysqlcppconn.lib in my c++ project. However, when I put use functionality from the library I get an error:
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol _mysql_init#4 referenced in function "public: void __thiscall Achievement::set(void)" (?set#Achievement##QAEXXZ) zombie C:\Users\jorda\OneDrive - Limerick Institute Of Technology\College\Final Year Project\Achievement_Libary\Copy - Copy\zombie\Achievement.obj 1
The code I'm using:
MYSQL* conn;
MYSQL_ROW row;
MYSQL_RES* res;
conn = mysql_init(0);
The errors seems to come from the mysql_init(0);
I've tried both the 32 and 64-bit version of the library but both give the same error. I'm not sure if I need to put some dlls inside the executable directory. I've tried putting libssl-1_1.dll & libcrypto-1_1.dll from both the 32 bit and 64-bit files as that's what one tutorial did however this did not work.
Would anyone know the process of trying to use the C++ connector in a visual studio project? Any help is appreciated. Here are the lib and input paths from the Linker
Would anyone know the process of trying to use the C++ connector in a visual studio project?
I suggest you could try the following steps:
1,Add the path to the header file to the Additional Include Directories(property - >c/c++ -> General -> Additional Include Directories)
2,Add the path to the .lib file to the Additional Library Directories (property -> linker -> General -> Additional Library Directories)
3,Add the name of the .lib file with its extension to Additional Dependencies (property -> linker -> input -> Additional Dependencies)
I suggest you could try to check if the file is in the location that you specified, or if you have provided the correct library path. And you couldn't mix 32 bit and 64 bit. Please make sure you're linking in 64-bit libraries with the 64-bit application, or change your app to 32-bit and link with the 32-bit libraries.

LNK1136 invalid or corrupt file

Trying to use .lib in Visual c++ CLR project.
This .lib is built in c++ builder 5, i have .lib file and .hpp file.
created visual c++ -> CLR -> class library project.
In properties following fields are added,
C/C++ -> General ->
Additional include directories = C:\Users\D2\source\repos\CLR\CLR\LIB
Linker -> Additional include directories = C:\Users\D2\source\repos\CLR\CLR\LIB
Input -> Additional Dependencies = lib0.lib
C:\Users\D2\source\repos\CLR\CLR\LIB, This location contains .hpp, .lib, .dll files.
And Builded,
Linker error is coming, LNK1136 invalid or corrupt file
As this error says, I checked no other application is using this library and specified the correct library name and path. I'm confused with this corrupt file word because the same library is working with c++ builder 5.
please give suggestions.

Visual Studio Additional Include Paths?

I'm working on an existing Visual Studio 12 "Solution" from another team..
In one of its "project"s,, there's a header file that includes a file from another static library projecet..
So Lets say the solution structure looks something like this:
Project A (Static Library Project)
\__ someFile.h
Project B (Static Library Project)
\__ someLibrary.h
In someFile.h,
...
#include "someLibrary.h"
...
and this loads the library successfully.. BUT this is strange because the path to someLibrary.h is NOT SPECIFIED anywhere in Project A's settings!!
I've checked Configuration Properties => VC++ Directories => Include Directories but path to someLibrary.h is NOT specified here..
Since Project A is a static library with NO cpp files (has only header files), It does not have a Configuration Properties => C++ => Additional Include Directory Option at all... (It only has the Librarian option)
And of course someLibrary.h is not in the same directory as someFile.h.
Finally, in Project A's Common Properties, Project B is not referenced either...
So my question is : How the hell does someFile.h know where someLibrary.h is?
How is it including it??
Is there any other places in project settings/etc where additional include directory can be specified..?
UPDATE:
when I right click on the #include statement and click "Open Document 'someLibrary.h'",
I do see a following VS error box:
File 'someLibrary.h' not found in current source file's directory or in build system paths.
Nevertheless,, there is NO build error, and Project A uses someLibrary.h with no problem!!

Visual Studio: Include .h or .cpp in two-project solution

I have a Visual Studio solution containing 2 project: main project and test (via googletest). In main project I have myclass.cpp and myclass.h files. When I'm trying to compile test project, there are bunch of LNK2019 errors when I include "myclass.h" in my test.cpp file, but everything works fine if I include "myclass.cpp" instead. Is that normal? As far as I know, including of .cpp files is not recommended and generally can be avoided. Any suggestions?
It's normal. If you have 2 projects, 2 binaries will be generated.
Don't include the cpp file.
Instead, link the binaries together.
main project - generates .lib file and either .dll or .exe.
test project - includes header from main. You need to add the .lib generated by main in the additional dependencies of the test project. Somewhere in the Project Settings - Linker Options - Additional Dependencies.
You can generate both .exe and .lib file from a single project. To do this you set:
exe in Linker -> General -> Output File
lib in Linker -> Advanced -> Import Library
You may also need to mark exported functions with __declspec( dllexport ) in the .exe project (see docs), otherwise compiler won't generate a .lib file.
Steps to Use Classes form another project (Add header and solver linker errors)
1) To be able to add the header from another project, first go to "Properties > c++ > General > Additional Include Directories" and add the directory that contains the header. Now you will be able to add the header of the class from the other project, but running the project will still cause Linker Errors.
2) Add __declspec(dllexport) before the class you are using for the other project. This can be added in the header file of that class. This should be added right before the function or variable or class name. Now you will get a lib file. (if placed in wrong place, you can get this warning: https://msdn.microsoft.com/en-us/library/eehkcz60.aspx)
3) "Properties > Linker > Additional Library Directories". Specify the location of the lib file that is generated.
4) "Properties > Linker > Input > Additional Dependencies”: Add the name of the lib file.

Mysterious relative path library dependency

After loading an existing MFC application in Visual Studio 2008, I am left with one linking error:
LINK : fatal error LNK1104: cannot open file '..\..\xpressmp\lib\xprm_rt.lib'
I have looked "everywhere", but I can't figure out where the relative path is set. The lib file is located in C:\xpressmp\lib, and I have added this directory both under Tools-Options->Projects and Solutions->VC++Directories->Library files and Project->Properties->Linker->Additional Library Directories. I also searched all files in the project to no avail.
I have the library file (xprm_rt.lib) listed under Additional Dependencies for both Debug and Release. I also tried adding the path there, but that did not help. I cannot find any #pragma comment-directives.
About the LNK1104, the file clearly does not exist in the location that the linker is searching. But I can't see why it is searching there (..\..\...) as I have not specified any relative paths.
Any help appreciated :-)
UPDATE:
In the project .vcproj file, I found the following xml:
<File RelativePath="..\..\XpressMP\lib\xprm_rt.lib"></File>
<File RelativePath="..\..\XpressMP\lib\xprs.lib"></File>
After deleting these lines (where were they set?), I was able to link successfully. Thanks for your help, it seems the relative library path was indeed being appended "automatically" by VS.
Thanks both of you, I think it was Nick that put me on the right track.
In the project properties, look under Configuration Properties -> Linker -> Input -> Additional Dependencies, for each of your project's configurations (Debug, Release, etc). Also, look for #pragma comment(lib, ...) directives in the code.
As you've added the C:\xpressmp\lib folder to the library search path in VC++ Directories, check that only the library file name is specified under Additional Dependencies, and this does not include the path (i.e, xprm_rt.lib, not ..\..\xpressmp\lib\xprm_rt.lib).
Also, have you tried each of the solutions in the LNK1104 error documentation?
It sounds like one of a couple possibilities to me:
The library itself is setting the lib include path via a #pragma comment(lib, ...) directive; search library headers to see if that's the case
You have a project for the library included in your solution which your main project is dependent on, and the relative library path is being appended automatically by VC; check the command line property page for the main project to see if that's the case
That's what I can think of which could cause the error; hope it helps.
Thanks for answering so swiftly!
I have the library file (xprm_rt.lib) listed under Additional Dependencies for both Debug and Release. I also tried adding the path there, but that did not help. I cannot find any #pragma comment-directives.
About the LNK1104, the file clearly does not exist in the location that the linker is searching. But I can't see why it is searching there (..\..\...)