Add obj file to linker input with cmake - c++

I have a cmake project that needs to link to a library that contains some .lib files and a .obj file. I've found some clues to how to link to a .obj file, but most solutions seem very complex.
All I really want to do is tell cmake to add the .obj file to the linker input in my Visual Studio project.
I tried linking it as I am doing with normal lib files:
target_link_libraries(Foo C:/a.lib C:/b.lib C:/c.obj)
However when I check the linker input in the generated VS project, cmake has removed the full-path and appended .lib to the obj file:
C:/a.lib
C:/b.lib
c.obj.lib
What's the simplest way of getting this result:
C:/a.lib
C:/b.lib
C:/c.obj
Note that this only needs to work with Windows and Visual Studio.

I was facing facing the same issue when I found your question. It is solved by the following line:
SET_TARGET_PROPERTIES(my_project PROPERTIES LINK_FLAGS "/link setargv.obj")
The link is appended to Additional Options in the Command Line Section from project's linker settings.

Related

Cannot open source file "GL/glew.h"

I'm getting into OpenGL and Visual Studio, and just got this warning and couldn't find any possible solution. I've added both GLEW and GLFW Libraries to the include directory, and then again in the input section of the Linker menu, in the project's properties. Anyways, Visual Studio seems unable to find any of them.
See these images - they explain it all.
Include Directories:
Linker Input:
The Problem:
GLEW Directory:
GLFW Directory:
All image link together
It's because your include directories should be pointing to where the header files are, not the .lib files.
Change your include directory to go to where the .h files are located, for me it's C:\...\glew-2.0.0\include\GL
The directories you currently have in it should instead go into Additional Library Directories located at linker->general in your options

Linking a .lib library to a project in Visual Studio

Somehow, even after going through a lot of materials, I could not understand one thing. I have a c++ library project in Visual Studio 2013. When I build it, it creates *.lib file. Now, there is another project where I need to link the .lib file. I created a folder called lib, dumped the .lib file in there and set the path of the lib folder to Properties->Linker->General->Additional Library Directories. Next I added the library file name *.lib in Properties->Linker->Input->Additional Dependencies. Now, building the project throws huge list of linker errors with message unresolved external symbol .... What is that I need to do more for linking the library?
I'm not sure what's the language your "another project" used, anyway, you should specifically set your *.lib file in Linker->Input->Additional Dependencies if you didn't explicitly load it in code.
If the both projects reside in the same solution the simplest option is to right-click of the project, go to to Properties, there go to Common Properties and in Framework and References add a reference to that library project. This will set the linker to link the .lib and adds a build dependency so the lib is always compiled before the executable.

Dependency from .lib to another .lib

I'm trying to build OpenCV v2.3.1 using Intel TBB and IPP. I used CMake to generate Visual Studio 2010 solution. Build is successful and I have opencv_core231d.lib among output.
Now I'm trying to link opencv_core231d.lib with my project. However, after specifying it in Linker -> Additional dependencies, I receive error LNK1104: cannot open file 'tbb_debug.lib'.
That's not the error about unresolved externals. Linker wants specific .lib file from me! How can that be?
I've done dumpbin /all of opencv_core231d.lib and for several sections it tells me:
Linker Directives
-----------------
...
/DEFAULTLIB:"tbb_debug.lib"
...
I tried to add tbb_debug.lib to /NODEFAULTLIB linker option of my project and it solved the problem. However, I just want TBB to be linked in opencv_core231d.lib.
The strange thing is I cannot find any reason why tbb_debug.lib is added to /DEFAULTLIB option of opencv_core231d.lib. I've searched all files in solution directory mentioning tbb_debug.lib as a substring, but the only matches was in generated .obj and .lib files - not in any source or project files. Where is the magic?
This question is not only related to OpenCV, but to whole process of working with .lib-files.
Update
There was a #pragma comment(lib, "tbb_debug.lib") directive in TBB include file _tbb_windef.h, so now I can understand from where did it go.
What I still don't understand is why it is not statically linked in opencv_core231d.lib? I've set Librarian -> Link Library Dependencies option to Yes. And there are no #pragma comment(lib, "tbb_debug.lib") directives in my project - I've checked preprocessor output.
Thanks.
There's probably a #pragma comment(lib, "tbb_debug") somewhere in one of the header files you are including.
This is to do with using the thread building blocks by Intel. See this blog post for more information: http://software.intel.com/en-us/blogs/2008/07/07/get-tbb-going-by-a-single-click/

Cannot link to lib file after upgrading to VS10

So I imported this VS9 solution into VS10 and VS10 would convert the whole thing into its new format for solution and project files. However, now it is giving me linker errors.
One project, a native C++ project, is using a set of header files and a .lib file to link to some external library. In the project, this library is specified by being put into a "Library" folder in the project. In VS9, this works fine, in VS10, it fails. The same lib is linked, however, when put into the "Additional Dependencies" setting in the Linker Input panel of the project's options.
I know the technique to drop lib files into the project for more than a decade. Has this stopped working with VS10?
No ,that still works in VS2010 (just tested it to make sure)!

glew32.lib linker error

I am writing a basic toon shader in OpenGL. I am using MSVC 2008. I have included the GLEW libraries. I have also set the additional dependencies in linker. But I am getting the following error:
LINK : fatal error LNK1104: cannot open file 'glew32.lib'
You need to set your linker to look in the correct place for the library. Either you don't have the lib, or your linker can't find it. Open your project properties dialog, go to linker, specify the lib as a dependency and provide the path to the correct lib folder.
you can also drag and drop the glew32.lib (or any other lib file of course) into your visual studio project and i think it will be automagically linked in and the linker will find it (which i think is your problem).
anyhow, i prefer setting my search directories by hand.
add this:
#pragma comment(linker, "/NODEFAULTLIB:libc.lib")
It will definitely solve your problem.