0

How can I create a lib folder and have lib.so in it? Here is my cmakelists file inside lib folder

project(Library) add_library(Library SHARED lib.cpp) target_include_directories(Library PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) 

In the main cmakelists file I write:

target_link_libraries(MyProject Library) set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib) 

but it doesn't work. The file is created inside the folder where make is running.

0

1 Answer 1

1

LIBRARY_OUTPUT_DIRECTORY is a target property, not a variable you set. Instead of

set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib) 

you need to use

set_target_properties(Library PROPERTIES LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib" ) 

However, if you want all the libraries built by your project to be put into that folder you can alternatively use

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/lib") 

somewhere at the top of your top-level CMakeLists.txt, as this variable sets the default value of the LIBRARY_OUTPUT_DIRECTORY target property for all targets defined after it has been set.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.