CMake - Can't link shared library (subdirectory)
I am using CLion and mingw-w64.
My executable's CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(test_exe)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "D:\test")
add_subdirectory(test_lib)
include_directories(test_lib/include;test_lib/deps/include)
link_directories(test_lib/deps/lib)
add_executable(test_exe main.cpp)
target_link_libraries(test_exe test_lib)
test_lib's CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(test_lib)
set(CMAKE_CXX_STANDARD 17)
include_directories(include;deps/include)
link_directories(deps/lib)
file(GLOB_RECURSE LIB_SOURCES "include/*.*" "src/*.*")
add_library(test_lib SHARED ${LIB_SOURCES})
target_link_libraries(test_lib libfreetype.a libpugixml.dll.a)
The problem is that when I add library with add_library(test_lib SHARED ${LIB_SOURCES})
I get undefined reference
errors but when I add the library with add_library(test_lib ${LIB_SOURCES})
it works perfectly.
An empty project links as expected (both SHARED and STATIC) but I wonder why this one is not working? Because of the libraries I link in the test_lib's CMakeLists.txt?
c++ cmake clion
add a comment |
I am using CLion and mingw-w64.
My executable's CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(test_exe)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "D:\test")
add_subdirectory(test_lib)
include_directories(test_lib/include;test_lib/deps/include)
link_directories(test_lib/deps/lib)
add_executable(test_exe main.cpp)
target_link_libraries(test_exe test_lib)
test_lib's CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(test_lib)
set(CMAKE_CXX_STANDARD 17)
include_directories(include;deps/include)
link_directories(deps/lib)
file(GLOB_RECURSE LIB_SOURCES "include/*.*" "src/*.*")
add_library(test_lib SHARED ${LIB_SOURCES})
target_link_libraries(test_lib libfreetype.a libpugixml.dll.a)
The problem is that when I add library with add_library(test_lib SHARED ${LIB_SOURCES})
I get undefined reference
errors but when I add the library with add_library(test_lib ${LIB_SOURCES})
it works perfectly.
An empty project links as expected (both SHARED and STATIC) but I wonder why this one is not working? Because of the libraries I link in the test_lib's CMakeLists.txt?
c++ cmake clion
add a comment |
I am using CLion and mingw-w64.
My executable's CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(test_exe)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "D:\test")
add_subdirectory(test_lib)
include_directories(test_lib/include;test_lib/deps/include)
link_directories(test_lib/deps/lib)
add_executable(test_exe main.cpp)
target_link_libraries(test_exe test_lib)
test_lib's CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(test_lib)
set(CMAKE_CXX_STANDARD 17)
include_directories(include;deps/include)
link_directories(deps/lib)
file(GLOB_RECURSE LIB_SOURCES "include/*.*" "src/*.*")
add_library(test_lib SHARED ${LIB_SOURCES})
target_link_libraries(test_lib libfreetype.a libpugixml.dll.a)
The problem is that when I add library with add_library(test_lib SHARED ${LIB_SOURCES})
I get undefined reference
errors but when I add the library with add_library(test_lib ${LIB_SOURCES})
it works perfectly.
An empty project links as expected (both SHARED and STATIC) but I wonder why this one is not working? Because of the libraries I link in the test_lib's CMakeLists.txt?
c++ cmake clion
I am using CLion and mingw-w64.
My executable's CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(test_exe)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "D:\test")
add_subdirectory(test_lib)
include_directories(test_lib/include;test_lib/deps/include)
link_directories(test_lib/deps/lib)
add_executable(test_exe main.cpp)
target_link_libraries(test_exe test_lib)
test_lib's CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
project(test_lib)
set(CMAKE_CXX_STANDARD 17)
include_directories(include;deps/include)
link_directories(deps/lib)
file(GLOB_RECURSE LIB_SOURCES "include/*.*" "src/*.*")
add_library(test_lib SHARED ${LIB_SOURCES})
target_link_libraries(test_lib libfreetype.a libpugixml.dll.a)
The problem is that when I add library with add_library(test_lib SHARED ${LIB_SOURCES})
I get undefined reference
errors but when I add the library with add_library(test_lib ${LIB_SOURCES})
it works perfectly.
An empty project links as expected (both SHARED and STATIC) but I wonder why this one is not working? Because of the libraries I link in the test_lib's CMakeLists.txt?
c++ cmake clion
c++ cmake clion
asked Nov 21 '18 at 16:42
bugraarslan
486
486
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
When you build a static library, there is no linking taking place. It doesn't check that you have all required libraries.
When you do the same for shared librarie,s then on some platforms (like Windows, or on Linux with -X defs, I think), you need to solve all references.
And you have a shared library.
I did not get what should I do. Can you explain a little more or post a link about?
– bugraarslan
Nov 21 '18 at 19:11
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416784%2fcmake-cant-link-shared-library-subdirectory%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
When you build a static library, there is no linking taking place. It doesn't check that you have all required libraries.
When you do the same for shared librarie,s then on some platforms (like Windows, or on Linux with -X defs, I think), you need to solve all references.
And you have a shared library.
I did not get what should I do. Can you explain a little more or post a link about?
– bugraarslan
Nov 21 '18 at 19:11
add a comment |
When you build a static library, there is no linking taking place. It doesn't check that you have all required libraries.
When you do the same for shared librarie,s then on some platforms (like Windows, or on Linux with -X defs, I think), you need to solve all references.
And you have a shared library.
I did not get what should I do. Can you explain a little more or post a link about?
– bugraarslan
Nov 21 '18 at 19:11
add a comment |
When you build a static library, there is no linking taking place. It doesn't check that you have all required libraries.
When you do the same for shared librarie,s then on some platforms (like Windows, or on Linux with -X defs, I think), you need to solve all references.
And you have a shared library.
When you build a static library, there is no linking taking place. It doesn't check that you have all required libraries.
When you do the same for shared librarie,s then on some platforms (like Windows, or on Linux with -X defs, I think), you need to solve all references.
And you have a shared library.
answered Nov 21 '18 at 16:47
Matthieu Brucher
12.7k22140
12.7k22140
I did not get what should I do. Can you explain a little more or post a link about?
– bugraarslan
Nov 21 '18 at 19:11
add a comment |
I did not get what should I do. Can you explain a little more or post a link about?
– bugraarslan
Nov 21 '18 at 19:11
I did not get what should I do. Can you explain a little more or post a link about?
– bugraarslan
Nov 21 '18 at 19:11
I did not get what should I do. Can you explain a little more or post a link about?
– bugraarslan
Nov 21 '18 at 19:11
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416784%2fcmake-cant-link-shared-library-subdirectory%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown