Linker with user32.lib - visual-c++

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.

Related

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

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

How to use libgit2 from a native C++ application on Windows? (Microsoft VC++)

Summary: Is there any tiny example on how to build the Win32 C++ console application that uses the libgit2 library (sources available at GitHub)?
I have followed the readme and the wiki on how to build the library on Windows using the CMake, and it worked smoothly (only a single unit-test error).
Now, I want to build a simple console application that uses the library -- using Microsoft Visual Studio C++ 2010 (the.vcxproj and the.sln). I have found the general.c code in the libgit2 examples, and I would like to do the same from my C++ application. No success -- I feel really stupid today...
I have noticed there is libqgit2 for C++ and Qt. Is there anything similar for pure C++? Or is there a way to use the C library from C++ application?
Update: I have renamed the general.c to general.cpp, added the libgit2 include path to the project and the path to the .lib files, changed the #include <stdio.h> to #include <cstdio>, and compiled. The following link errors appear:
1>------ Build started: Project: libgit2_general, Configuration: Debug Win32 ------
1>general.obj : error LNK2019: unresolved external symbol _git_repository_free referenced in function _main
1>general.obj : error LNK2019: unresolved external symbol _git_config_get_string referenced in function _main
1>general.obj : error LNK2019: unresolved external symbol _git_config_get_int32 referenced in function _main
1>general.obj : error LNK2019: unresolved external symbol _git_config_open_ondisk referenced in function _main
1>general.obj : error LNK2019: unresolved external symbol _git_strarray_free referenced in function _main
... etc.
1>general.obj : error LNK2019: unresolved external symbol _git_repository_open referenced in function _main
1>general.obj : error LNK2019: unresolved external symbol _giterr_last referenced in function "void __cdecl check_error(int,char const *)" (?check_error##YAXHPBD#Z)
1>D:\Tutorial\libgit2_general\Debug\libgit2_general.exe : fatal error LNK1120: 56 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
This strongly suggests a calling convention mismatch to me. libgit2 uses __stdcall by default, for a number of reasons, while Visual Studio defaults to creating projects that use the __cdecl calling convention. While your program can use either calling convention and successfully call libgit2 using a different one, the easiest solution is probably just to use the same calling convention for both.
When you configure libgit2, you can turn off the STDCALL flag, which will cause it to emit a library built with __cdecl calling conventions:
cmake %PATH_TO_LIBGIT2_SOURCE% -DTHREADSAFE=ON -DSTDCALL=OFF
cmake --build .
It's a little surprising if you generated the project from CMake, bit it could be that you're not linking to libgit2.lib. Make sure you have git2.dll in Project Properties -> Configuration Properties -> Linker -> Input -> Additional Dependencies.

Having problems with yaml.cpp lib in c++

I am having a hard time trying to use yaml-cpp 0.3.0 on my project
I downloaded yaml, and built it like http://code.google.com/p/yaml-cpp/ said, with VS 9 2008 WIN 64. So, i got the yaml-cpp.dll and the yaml-cpp.lib
I have a c++ project on VS 2010 express, and i am trying to link the library:
I go to project properties - c/c++ general and additional include directories that have yaml-cpp header files. Then i go to linker and add path to my lib directory, then I go to linker - input and add my .lib file, then i go to VC++ Directories and add path to my lib directory in Library directories and Reference directories
Then i try to build this simple code:
std::ifstream fin("test.yaml");
YAML::Parser parser(fin);
YAML::Node doc;
while(parser.GetNextDocument(doc)) {
//do nothing yet
}
I got several linking problems, like this:
error LNK2019: unresolved external symbol "public: __thiscall YAML::Node::Node(void)" (??0Node#YAML##QAE#XZ) referenced in function "public: __thiscall Parser::Parser(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Parser##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
error LNK2019: unresolved external symbol "public: __thiscall YAML::Parser::~Parser(void)" (??1Parser#YAML##QAE#XZ) referenced in function "public: __thiscall Parser::Parser(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (??0Parser##QAE#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z)
Can anyone help me? I am banging my head against a wall here.
As you said you've got a DLL from YAML, I assume you specified -DBUILD_SHARED_LIBS=ON when you built with VS2008, so you ended up with a lib for dynamic linking (to the DLL at runtime) rather than static linking (at compile time).
If the above is correct, it may be differences between VS2008 and VS2010 that are causing a problem. For example, see this post here. To quickly see if this is the cause, in your VS2010 project properties, set the Platform Toolset to V90 and see if that helps.
Also, make sure you compiled both projects for the same CPU - i.e. both for 32-bit or both for 64-bit.

Using IrrKlang with Ogre

I'm trying to set up sound in my Ogre3D project. I have installed irrKlang 1.4.0 and added it's include and lib directories to my projects VC++ Include and Library directories, but I'm still getting a Linker error when I attempt to build. Any suggestions?
(Error 4007 error LNK2019: unresolved external symbol
"__declspec(dllimport) class irrklang::ISoundEngine * __cdecl
irrklang::createIrrKlangDevice(enum
irrklang::E_SOUND_OUTPUT_DRIVER,int,char const *,char const *)"
(_imp?createIrrKlangDevice#irrklang##YAPAVISoundEngine#1#W4E_SOUND_OUTPUT_DRIVER#1#HPBD1#Z)
referenced in function "public: __thiscall
SoundManager::SoundManager(void)" (??0SoundManager##QAE#XZ)
Okay, after looking at this for awhile it seems I was making two mistakes.
The lib directory for irrKlang is divided in two, so instead of adding (IRRKLANGDIRECTORY)\lib to my library directories, I should have been using (IRRKLANGDIRECTORY)\lib\Win32-visualStudio.
Including the lib directory wasn't sufficient, I also needed to specify the use of the irrklang library file at the top of my class (#pragma comment(lib, "irrklang.lib")).

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