Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add obj file to linker input with cmake

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.

like image 413
pqvst Avatar asked Oct 16 '25 10:10

pqvst


1 Answers

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.

like image 160
sebkraemer Avatar answered Oct 18 '25 06:10

sebkraemer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!