Keep VC++ 2005 static library and your application in separate solutions - visual-c++

I have successfully built a static library as described in this walkthrough:
http://msdn.microsoft.com/en-us/library/ms235627%28v=vs.80%29.aspx
In the example above, both the static library and the application are located within the same solution but I prefer to keep them in separate solutions. After separation, I can compile but cannot link, here is the error:
main.obj : error LNK2019: unresolved external symbol…
Then I tried the project level setting of my application C/C++ / General / Additional include directories to where my .h file resides.
I also set .. Linker / General / Additional library directories to where my .lib file is at.
I finally set .. Linker / Input / Additional dependencies to where my .lib file is at.
Again, I could compile but not link. Here is the entire link error:
LINK : warning LNK4075: ignoring '/INCREMENTAL' due to '/OPT:ICF' specification
main.obj : error LNK2019: unresolved external symbol "public: static double __cdecl MathFuncs::MyMathFuncs::Add(double,double)" (?Add#MyMathFuncs#MathFuncs##SANNN#Z) referenced in function _main
Release\StaticLibraryApp.exe : fatal error LNK1120: 1 unresolved externals

Your project should link against the library project. In the 2nd project properties, add a library path where .lib file is stored and also include path for header path. This should resolve the issue. Also make 1st project dependent on 2nd solution.
Have a look at below article how to add libraries:
http://www.lavishsoft.com/wiki/index.php/Visual_Studio_Paths

Related

Problem compiling exiv2 code in VS 2022: Undefined Reference/symbol error

I have some code in Linux that uses exiv2 to read the metadata of a folder full of photos, depending on requirements it can reconstruct missing metadata, and stamp a logo as well as lat/long onto the photos. I'm trying to port it into windows visual studio so that I can make a GUI and let other people use it.
I downloaded the MSVS source code for exiv2, I've added the include folder and lib folders both in the include line and the linker line in the project properties dialogue. When I try to compile I get an undefined reference error whenever an EXIV2 object is called.
I'm guessing I have some sort of linking or library building issue. I built it on linux using g++ and had no problems. If I weren't trying to make a GUI I'd probably just get a windows version of g++ to compile with.
This is one of the error messages I'm getting.
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "__declspec(dllimport) public: class std::_List_iterator<class std::_List_val<struct std::_List_simple_types > > __thiscall Exiv2::ExifData::begin(void)" (_imp?begin#ExifData#Exiv2##QAE?AV?$_List_iterator#V?$_List_val#U?$_List_simple_types#VExifdatum#Exiv2###std###std###std##XZ) referenced in function "int __cdecl uptake(class std::vector<struct EANphoto,class std::allocator > &,char *,char *)" (?uptake##YAHAAV?$vector#UEANphoto##V?$allocator#UEANphoto###std###std##PAD1#Z) CAPconsole C:\Users\ [redacted] \source\repos\CAPconsole\CAPconsole.obj 1
I've tried adding include files for both the "include" and the "lib" folders to both the include line and to the linker. I also tried to compile the sample program that came with Exiv2, and I get the same error,so I'm guessing it's a VS setting issue.
So, the way to do this is as follow:
In "Properties" … "C/C++" … "General" … "Additional Include Directories", add the include and lib folders, and do the same in
"Linker" … "Additional Library Directories".
Finally, in "Linker" … "Command Line" … "Additional Options", write in "exiv2.lib".

How to make JsonCPP works in MFC c++ project

I was able to create a test WinApp using JsonCPP (https://github.com/open-source-parsers/jsoncpp) to parse a json file.
However, when I implemented similar in an MFC C++ project with C/C++ -> Precompiled Headers option set to Use Precompiled Header(/Yu) in VS2008, it fails with this error:
c:\users\user1\documents\visual studio 2008\projects\jsonutility\jsonutility\jsonTest.cpp(371) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
If I add '#include "stdafx.h"' to my JsonTest.cpp, I will get this error:
JsonTest.obj : error LNK2019: unresolved external symbol "public: class Json::Value & __thiscall Json::Value::operator[](char const *)" (??AValue#Json##QAEAAV01#PBD#Z) referenced in function "public: void __thiscall JsonTest::readConfig(char const *)" (?readConfig#JsonTest##QAEXPBD#Z)
I have tried for almost 2 days now but no success.
I had added the following in my Additional Include Directories:
C:\Users\User1\Documents\Visual Studio 2008\Projects\JsonUtility\ReadingJson\dist
C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include
C:\usr\jsoncpp-master\include
I seems like you didn't include the JSONCPPs *.cpp file into your project (they have to be compiled and linked). If the library gets compiled to a static library, you have to tell the linker what to link.

SFML linker problems on eclipse VC++

I am trying to use the SFML library for audio in my project.
I am developing in eclipse juno for c++ and am using SFML v1.6.
I added sfml-audio-d.lib, sfml-main-d.lib, and sfml-system-d.lib into
C/C++ General > paths and symbols>libraries
I also defined a macro named SFML_DYNAMIC into
C/C++ Build>Settings>C++ Compiler>Preprocessor 'Defines /D' section
I added the directory that contains all the dlls into the PATH environment variable.
In my code I make use of sf::SoundBuffer, but when I try to build the project I get the following linker error:
Chunk.obj : error LNK2001: unresolved external symbol "private: static class sf::SoundBuffer * Chunk::breakBlockSound" (?breakBlockSound#Chunk##0PAVSoundBuffer#sf##A)
MyProject.exe : fatal error LNK1120: 1 unresolved externals
Had to rebuild the project in VS2010 before using it. Works now.

Linker with user32.lib

I am trying to create a windows application but am getting a linker error as follows:
1>test_project.obj : error LNK2019: unresolved external symbol "int __cdecl run(void)" (?run##YAHXZ) referenced in function _WinMain#16
I assume this is because user32.lib is not linking correctly, but I have added it to linker->input->additional dependencies and added the directory containing it to library directories. Help would be appreciated.
I don't think this has anything to do with user32.lib. Most likely your program contains a forward declaration of function int run(void); which you never define yet trying to call from your WinMain(...) procedure.

Library linker errors driving me mad

It's me again. I'm back with an all new project and an all new problem.
I am trying to implement something for Growl. Either using a static or shared library (both are provided). I included the necessary header and linked to the library. (2 ways actually, once through the project properties and the other through a pragma statement). However, im still receiving the following linker errors:
error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall Growl::Growl(enum Growl_Protocol,char const * const,char const * const,char const * * const,int)" (__imp_??0Growl##QAE#W4Growl_Protocol##QBD1QAPBDH#Z)
error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall Growl::~Growl(void)" (__imp_??1Growl##QAE#XZ)
fatal error LNK1120: 2 unresolved externals
The line of code that is causing these linker errors is this line:
const char *n[2] = { "username" , "password" };
Growl *growl = new Growl(GROWL_TCP,NULL, "Appname", (const char **const)n,2);
The header file is being included at the top of the file and I am linking with the following line:
#include "..\\..\\..\\libs\\Growl\\growl++.hpp"
#pragma comment(lib, "..\\..\\..\\libs\\Growl\\libgrowl-static++.lib")
The header source can be found here:
https://github.com/psinnott/gntp-send/blob/master/headers/growl%2B%2B.hpp
I retrieved the pre-built binaries from the following page:
https://github.com/psinnott/gntp-send/wiki/Windows
Some extra info: I do have my Project Propeties character set to use Multi-Byte Character Set, im under the assumption this shouldn't affect anything. This is also a Win32 Console application.
Where am I going wrong?
Update:
Found this via google:
http://groups.google.com/group/growl-for-windows/browse_thread/thread/6c48a62454d062f1
Followed the instructions:
Added the libgrowlstatic.lib (alongside libgrowlstatic++.lib)
Added the pre-processor definitions, GROWL_STATIC and GROWL_CPP_STATIC
Got lots of error including:
LINK : warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
fatal error LNK1169: one or more multiply defined symbols found
So I added the following line to Project properties, Linker, Command Line:
/NODEFAULTLIB:MSVCRTD /NODEFAULTLIB:LIBCMT
Now im getting alot more errors including some of the following:
libgrowl-static.lib(tcp.obj) : error LNK2019: unresolved external symbol _atoi referenced in function _growl_tcp_parse_hostname
libgrowl-static.lib(tcp.obj) : error LNK2019: unresolved external symbol _strchr referenced in function _growl_tcp_parse_hostname
libgrowl-static.lib(growl-static.obj) : error LNK2019: unresolved external symbol _fseek referenced in function _growl_tcp_register
libgrowl-static.lib(growl-static.obj) : error LNK2019: unresolved external symbol _fopen referenced in function _growl_tcp_register
libgrowl-static.lib(growl-static.obj) : error LNK2019: unresolved external symbol _strcpy referenced in function _growl_udp_notify
Been at this for several hours and can't seem to figure it out. 10+ views and no replies?
I swear im not being lazy. I looked into one of the answers provided about libraries but didn't have much luck. Nothing explained why this is acting the way it is. Please help!
#pragma comment(lib, "..\\..\\..\\libs\\Growl\\libgrowl-static++.lib")
There is a clear mismatch between the #pragma and the way your code is getting compiled. The name of the library strongly suggests this is a static link library, the "static" in the name makes that clear. The error messages however talk about __declspec(dllimport), a directive that's used when you compile code that #includes a header that assumes the code lives in a DLL instead of a static link library.
The other errors you are getting bear this out as well. The Project + Properties, C/C++, Code Generation, Runtime Library setting matters. You are using the /MD setting, a setting that's appropriate when you work with DLLs. The library no doubt was compiled with /MT, a setting appropriate when you create a monolithic EXE that doesn't use DLLs. You are trying to link two chunks of code that were built with conflicting settings, the linker falls over when trying to deal with this. It explicitly says so in an error message.
You'll need to either dig up the DLL version of the .lib or use /MT consistently in the rest of your code. There's usually a #define that tells the .h file which version of the .lib you intend to link.
This is working for me. It assumes you want to use the static libraries and not the dll.
Properties -> Configuration -> Properties -> VC++ Directories
Add directory of unzipped sdk to include and library directories
Properties -> Configuration -> Properties -> C/C++ -> Preprocessor
Add GROWL_STATIC and GROWL_CPP_STATIC to preprocessor definitions
Properties -> Configuration -> Properties -> C/C++ -> Code generation
Change runtime library to multi threaded ( /MT or /MTd )
Properties -> Configuration -> Properties -> Linker -> Input
Add ws2_32.lib , libgrowl-static.lib and libgrowl-static++.lib to additional dependencies

Resources