Skip to content

Instantly share code, notes, and snippets.

@jlgerber
Last active December 14, 2023 07:52
Show Gist options
  • Star 31 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save jlgerber/eafc4ee2b9954e27dd2bb009496b1b03 to your computer and use it in GitHub Desktop.
Save jlgerber/eafc4ee2b9954e27dd2bb009496b1b03 to your computer and use it in GitHub Desktop.
cmake - handling executable and library with same name
# Lets say we want to add a library and an executable, both with the same name.
# In this example, it is resman
add_library(resman ${src_cpps} ${src_hpps} )
target_link_libraries(resman ${Boost_LIBRARIES} ${LIBYAML} ${LIBFMT})
#
# Add resman executable
#
# We call the executable resman-bin
add_executable(resman-bin main.cpp )
target_link_libraries(resman-bin resman)
# now we rename resman-bin executable to resman using target properties
set_target_properties(resman-bin
PROPERTIES OUTPUT_NAME resman)
#
@Ashark
Copy link

Ashark commented Apr 29, 2017

Thank you

@chichivica
Copy link

Thanks!!

@saxbophone
Copy link

Cheers!

@xahon
Copy link

xahon commented Sep 17, 2019

ty

@MartinHerren
Copy link

Thanks !

@acarrillo
Copy link

👏

@roman-orekhov
Copy link

OUTPUT_NAME doesn't work with MSVC as it issues /implib with the same name as the library resulting in LNK1149 error. What does work is to use RUNTIME_OUTPUT_NAME

@TheSalvator
Copy link

👏

@Mark-ZU
Copy link

Mark-ZU commented May 2, 2022

thank you!

@gxosty
Copy link

gxosty commented Sep 30, 2023

Heh, thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment