I have a solution with two projects on VS2010.
The main project references and depends on the second one, which is built as a static library. The second one uses a static third-party library that is not build within the solution, but is only referenced in the second project's linker settings.
If I try to generate the solution, VS fails and indicates that he didn't find the third-party library. I do not understand why, since the second project's compiled static lib is big enough and seems to "contain" the 3rd-party library.
So far, I see only two solutions to my problem, which I would rather avoid:
Add the 3rd-party library to the main project's linker settings
Include the whole 3rd-party library in my solution and compile it with
Is there any other way to resolve this problem?
EDIT : The problem occurs when compiling the main project, the compiler outputs : LINK : fatal error LNK1104: cannot open file 'wxbase29u.lib' (I'm using wxWidget in my second project)
EDIT2 : I put the -verbose option for linking on, and it seems like the references to the 3rd-party library actually still exists in Project2.lib :
Searching ..\MyAppConfig\Bin\Win32\Release\MyAppConfig.libĀ :
"public: static void __cdecl ConfigWindow::Open(void)" (?Open#ConfigWindow##SAXXZ) found
Referenced in main.obj
Loaded MyAppConfig.lib(configWindow.obj)
/DEFAULTLIB:wxbase29u processed
/DEFAULTLIB:wxbase29u_net processed
/DEFAULTLIB:wxbase29u_xml processed
/DEFAULTLIB:wxregexu processed
/DEFAULTLIB:wxexpat processed
/DEFAULTLIB:wxjpeg processed
/DEFAULTLIB:wxpng processed
/DEFAULTLIB:wxtiff processed
/DEFAULTLIB:wxzlib processed
...
...
LINK : fatal error LNK1104: cannot open file 'wxbase29u.lib'
Funny thing is that I don't even use the other wxWidgets libraries in Project2, but visual studio seems to be searching for all of them though :/
Here's how you should setup your project:
Project 1 (main)
Additional dependencies: Project2.lib
Project 2
Additional dependencies: ThirdParty.lib
Build order: Project 2 -> Project 1
If your project is setup like that and it does not link, then it just means the path to your libraries isn't correctly set (under "Additional include directories"). So just make sure that your project additional dependencies are correctly set and that the include directories point to the place where the libraries you need are located.
Related
I am trying to create a VS2019 project with ImageMagick (Magick++) as a statically linked library.
I have followed the directions from https://github.com/ImageMagick/ImageMagick-Windows.
In the wizard configurator I requested:
Build Type: Static Multi-threaded runtimes
Kept most settings to the default beyond that.
In my project I have set the header file include path to include:
C:\developer\ImageMagick\ImageMagick\
C:\developer\ImageMagick\ImageMagick\Magick++\lib
I have added library paths of:
C:\developer\ImageMagick\VisualMagick\lib
and I have added the relevant 3 library files for debug and release.. debug shown below:
CORE_DB_Magick++_.lib
CORE_DB_MagickCore_.lib
CORE_DB_MagickWand_.lib
In code I have:
#include <Magick++.h>
...
char szImageMagickLIBDirectory[MAX_PATH];
strcpy_s(szImageMagickLIBDirectory, MAX_PATH, "C:\\developer\\ImageMagick\\VisualMagick\\lib");
Magick::InitializeMagick(szImageMagickLIBDirectory);
Unortunately I get many LNK2001 unresolved external symbol errors during linking.
example:
LNK2001 unresolved external symbol UnregisterGRADIENTImage <myProjectName> <my_project_path>\CORE_DB_Magick++_.lib(static.obj) 1
Does anyone have information on how to setup a VS project for ImageMagick:x64-windows-static library use?
My backup plan (as you may deduce from my vcpkg notation) will be to use GraphicsMagick.
Well I feel a right idiot!
My mistake was thinking that the all the additional LIBs had been compiled into the 3 key LIBs commonly referenced and used by ImageMagick. That simply isnt the case! Gah! The very simple answer is to add all thirty odd static libraries to the project! Thats all!
I honestly thought I was dealing with some complex Linker settings issue, when the problem was simply my arrogant assumption!
I must now consume coffee to stave off the mind altering dumbness I feel!
EDIT:
Updated post to avoid linking to third party sites and to collect all required information here.
Any information is appreciated. If you need more info, please inform me and I will edit the post with the new details.
Here is some useful information to start with.
Errors.
Source code.
I am trying to use a third party SDK consisting of one lib file and essentially one header file. I manage to get the intellisense to work, but I get linker errors even though I have modified my project's build.cs file to add the library path.
public OculusTest(TargetInfo Target)
{
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
// Add static libs
PublicAdditionalLibraries.Add(Path.Combine(ThirdPartyPath, "RPLidar/Libraries", "rplidar_driver.lib"));
// Add a path with the .h that has the function definitions
PublicIncludePaths.Add(Path.Combine(ThirdPartyPath, "RPLidar", "Includes"));
}
I also checked if I was missing something, but in a standalone C++ project I use the same files and only the same files and it does work. The files in question are
RPLidar.h and rplidar_driver.lib
As such I assume the error is in me failing to tell the Unreal compiler where to find the lib file.
Thank you in advance for all information regarding this way too stubborn error.
I finally found my error.
After checking that the same version of VSC++ was used to compile both programs and that I checked that it was in the correct configuration I changed one extra thing that made it all work out.
Instead of compiling to a multi threaded LIB file, I compiled the code as a DLL file.
I did it by opening the LIB project properties and going to C/C++ -> Code Generation -> Runtime Library and setting it to Multithreaded DLL (/MD).
Under General I set the configuration type to be a static library (.lib).
So currently I'm trying to use the VISA library from National Intruments and the IVI Foundation to read/write commands to various external devices.
I am relatively novice with my IDE: Microsoft Visual C++ Express 2010 and this is my first time trying to use a third party library that requires more than a .h import.
Basically I have a directory with 3 header files, a directory with 3 .lib libraries and a directory with 7 DLLs. They have no documentation as to what any of the individual files do, only the library as a whole. So, I need to be able to get all of these files associated with my project.
Currently I have all the headers imported in my header file and the header directory added to the include directories in the project properties. I also have the directory containing the .lib files added to the library directories in the project properties. I assumed that .lib files would link to the DLLs, but apparently that is not the case because I'm getting the error:
VISA Console 2.obj : error LNK2019: unresolved external symbol _viOpenDefaultRM#4 referenced in function _wmain
This error occurs when using any function from the library. Here is my code currently:
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
ViStatus status;
ViSession defaultRM, instr;
status = viOpenDefaultRM(&defaultRM);
return 0;
}
The project will build when I comment out the viOpenDefaultRM command, so I assume that means I can use the objects from the library and not the commands. Since I have the 3 object declarations that build just fine.
Okay this is all my information, hopefully someone can help and hope this helps someone else!
In addition to having the directory for the .lib file(s) added to the library directories property, you need to also add the actual libraries that the linker should search.
Add the libraries to the project's
Configuration Properties | Linker | Input | Additional Dependencies
field.
The DLLs are not necessary for the build process, but to run the program they should be in a directory inthe PATH or in the same directory as the program file.
Have you added to the project properties the additional dependecies?
Under "Linker->Input" find "Additional Dependecies" and place there the libs that you got from
I have been able to work in the same project for sometime now, writing and successfully running c++ code. However, I discovered that I am still missing some essentials on how to export my .h files to another project and successfully use them in there.
I created a second project, project B to test the classes I have in project A.
visual c++: #include files from other projects in the same solution
I added the path of the header file in Project A into the Additional Include Directories(C\C++>general and Linker>general) section in the project configuration of Project B. I tried following the tutorials on this page http://msdn.microsoft.com/en-us/library/ms235636.aspx but I still end up with the error below
** LINK : fatal error LNK1104: cannot open file 'C:\Users\LaC\Projects\OSGB\Debug\OSGB.lib**
I would appreciate any help in understanding exactly how this is done so that in future, when I encounter this problem, I can know how to troubleshoot.
The code below is all I am working with.
IN PROJECT A
=============
//Utility.h
class Utility
{
private:
protected:
public:
Utility(void);
~Utility(void);
double square_root (const double);
};
//Utility.cpp
#include "StdAfx.h"
#include "Utility.h"
Utility::Utility(void)
{
//do nothing for now
}
Utility::~Utility(void)
{
//do nothing for now
}
double Utility::square_root (const double)
{
return 0;
}
IN PROJECT B
===============
#include "gtest/gtest.h"
#include "Utility.h"
TEST (SquareRootTest, PositiveNos) {
Utility u;
EXPECT_EQ (50.3321, u.square_root (2533.310224));
}
There are two (general) ways to include files into your project:
Make them a part of your project (adding them from the solution explorer) OR
Import them as a library (static or dynamic linking)
If you make them part of your project, then you have to add the header and the source files in order for the project to compile correctly. However, that's usually not what you want to do, as it defeats the purpose of having external libraries.
The second case is to use the external libraries, which requires that you:
Include the header files which are exported by the library in your C++ properties.
For static linking: you also have to include the *.lib file (the output of building the library) in the Linker properties.
OR
For dynamic linking: see tutorial.
So remember: there are two parts to building a C++ project- compiling and linking.
Compiler Errors:
If you get an error whose code starts with C* (e.g. C1083) and is related to problems header with the files, then check the Properties-> C/C++ -> General -> Additional Include Directories.
Linker Errors:
If you get an error whose code starts with LNK*, then check
Properties -> Linker -> General -> Additional Library Directories (make sure that this points to where the *.lib file is located)
AND
Properties -> Linker -> Input -> Additional Dependencies (make sure that the *.lib file is added here).
If you're dynamically linking, then check that you're correctly referencing the DLL.
So in your case, you have to determine if you're linking statically or dynamically and then make the appropriate references. So ware you getting those header files from a dynamically library or a static library?
When the linker emits unresolved external symbol for a symbol that lives in another library (DLL or shared library), this indicates that you need to link your app to that other library's .lib file. That is most likely what's happening here.
For more information see:
(MSDN) Walkthrough: Creating and Using a Dynamic Link Library (C++)
I was advised by some of you not to long ago to use FreeImage as a library for image processing in C++.
I now have some trouble in getting the library to work (still relatively new here).
I've tried loading the various vcxproj and sln tiles and they gave me a blank project. Since there isn't any installation instructions provided for that, I gave up on making it a visual studio solution.
I next tried the old-fashion way of compiling the source code using the Makefile and then adding "FreeImage/Source" to the linker. While the IDE does not raise any red flags when I call functions declared in FreeImage.h, it gave me a bunch of "error LNK2019: unresolved external symbol" during compilation, as if the functions do not exist. What I suspect is that the IDE could not find the .cpp files that define the said functions, but I still get that same problem when I added FreeImage/Source/FreeImage to the linker.
Now when I directly included some of the .cpp files (i.e. Plugin.cpp and FreeImage.cpp) for a test, I get even more unresolved external symbol errors as well as things like "inconsistent dll linkage" for this within... for example FreeImage.cpp:
const char * DLL_CALLCONV
FreeImage_GetVersion() {
static char s_version[16];
sprintf(s_version, "%d.%d.%d", FREEIMAGE_MAJOR_VERSION, FREEIMAGE_MINOR_VERSION, FREEIMAGE_RELEASE_SERIAL);
return s_version;
}
So, I am totally stuck. What am I doing wrong? I felt I've followed the adequate steps in adding library dependencies, such as adding the specific folders that are immediate parents to the relevant .h and .cpp files in C/C++ -> General -> Additional Included Directories and Linker -> General -> Addition Library Directories.
Some help will be greatly appreciated!
Using FreeImage v3.15.3 I had no problems converting the VS2008 project to VS2010.
Also the building worked as expected. But when I linked to the static lib, I got some unresolved externals. First I tried al kinds of tricks setting /MT /MD linking, but that did not solve these linking problem.
After reading Some Newbie's comment I dug into freeimage.h. There I found a macro switch FREEIMAGE_LIB that controls the calling conventions of the function.
Use a #define FREEIMAGE_LIB before including the freeimage.h file. That way you can easily static link to FreeImage.lib