CMake: library not createdHow to find a library with cmake?CMake link to external libraryCMake linking error (undefined reference to)cmake library linking orderCMake: Of what use is find_package() if you need to specify CMAKE_MODULE_PATH anyway?cmake add_library, followed by install library destinationCMake with gmockCMAKE no rule to make target for internal shared libraryLink a shared library with CMakeHow to connect the QuaZip library in CMake
Pronunciation of numbers with respect to years
Pressure inside an infinite ocean?
What happens if you dump antimatter into a black hole?
How was the quadratic formula created?
Independent, post-Brexit Scotland - would there be a hard border with England?
As matter approaches a black hole, does it speed up?
Using a microphone from the 1930s
Set collection doesn't always enforce uniqueness with the Date datatype? Does the following example seem correct?
How can I close a gap between my fence and my neighbor's that's on his side of the property line?
Is there an idiom that support the idea that "inflation is bad"?
What to use instead of cling film to wrap pastry
What is a smasher?
Manager is threatening to grade me poorly if I don't complete the project
Out of scope work duties and resignation
Why do people keep telling me that I am a bad photographer?
Can hackers enable the camera after the user disabled it?
Fitch Proof Question
How can I get a job without pushing my family's income into a higher tax bracket?
Does a card have a keyword if it has the same effect as said keyword?
Would glacier 'trees' be plausible?
What is the name of this hexagon/pentagon polyhedron?
Why do money exchangers give different rates to different bills?
How do I overfit?
What are the advantages of luxury car brands like Acura/Lexus over their sibling non-luxury brands Honda/Toyota?
CMake: library not created
How to find a library with cmake?CMake link to external libraryCMake linking error (undefined reference to)cmake library linking orderCMake: Of what use is find_package() if you need to specify CMAKE_MODULE_PATH anyway?cmake add_library, followed by install library destinationCMake with gmockCMAKE no rule to make target for internal shared libraryLink a shared library with CMakeHow to connect the QuaZip library in CMake
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I have a project directory A which has sub directories B and C.
I want C as a shared object library and let B use it.
The CMakeLists.txt looks like following -
A
...
add_subdirectory(C)
add_subdirectory(B)
...
[ 1) Does this ensure that C is cmake(ed) first and then B? ]
B
...
pkg_check_modules(C_LIB REQUIRED C)
target_link_libraries(B C_LIB)
...
C
...
add_library (C SHARED ./*c)
...
I get an error in build which says no package c found.
However, if I have directory C in the same hierarchy as A, I am able to get the linking of B and C properly.
I want to place my code in A and get the dependencies correct. What am I missing in my CMakeLists.txt?
cmake dependencies subdirectories
add a comment |
I have a project directory A which has sub directories B and C.
I want C as a shared object library and let B use it.
The CMakeLists.txt looks like following -
A
...
add_subdirectory(C)
add_subdirectory(B)
...
[ 1) Does this ensure that C is cmake(ed) first and then B? ]
B
...
pkg_check_modules(C_LIB REQUIRED C)
target_link_libraries(B C_LIB)
...
C
...
add_library (C SHARED ./*c)
...
I get an error in build which says no package c found.
However, if I have directory C in the same hierarchy as A, I am able to get the linking of B and C properly.
I want to place my code in A and get the dependencies correct. What am I missing in my CMakeLists.txt?
cmake dependencies subdirectories
add a comment |
I have a project directory A which has sub directories B and C.
I want C as a shared object library and let B use it.
The CMakeLists.txt looks like following -
A
...
add_subdirectory(C)
add_subdirectory(B)
...
[ 1) Does this ensure that C is cmake(ed) first and then B? ]
B
...
pkg_check_modules(C_LIB REQUIRED C)
target_link_libraries(B C_LIB)
...
C
...
add_library (C SHARED ./*c)
...
I get an error in build which says no package c found.
However, if I have directory C in the same hierarchy as A, I am able to get the linking of B and C properly.
I want to place my code in A and get the dependencies correct. What am I missing in my CMakeLists.txt?
cmake dependencies subdirectories
I have a project directory A which has sub directories B and C.
I want C as a shared object library and let B use it.
The CMakeLists.txt looks like following -
A
...
add_subdirectory(C)
add_subdirectory(B)
...
[ 1) Does this ensure that C is cmake(ed) first and then B? ]
B
...
pkg_check_modules(C_LIB REQUIRED C)
target_link_libraries(B C_LIB)
...
C
...
add_library (C SHARED ./*c)
...
I get an error in build which says no package c found.
However, if I have directory C in the same hierarchy as A, I am able to get the linking of B and C properly.
I want to place my code in A and get the dependencies correct. What am I missing in my CMakeLists.txt?
cmake dependencies subdirectories
cmake dependencies subdirectories
edited Mar 23 at 2:32
avariant
1,81831221
1,81831221
asked Mar 22 at 22:07
UnniboyUnniboy
12
12
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Does this ensure that C is cmake(ed) first and then B?
No. It doesn't ensure that there even is a C
nor B
project, and it doesn't ensure that they will build at all. It just sources/includes (in a special way) C/CMakeLists.txt
and B/CMakeLists.txt
files, that's all.
add_library (C SHARED ./*c)
This is invalid, unless you have a source file named *c
. You want:
file(GLOB sources ./*c)
add_library(C SHARED $sources)
The add_library doesn't understand globulations.
pkg_check_modules(C_LIB REQUIRED C)
target_link_libraries(B C_LIB)
This is strange. You don't have a pkg-config
modules named "C" do you? You probably want:
target_link_libraries(B C)
or better try to always explicit tell PUBLIC
or PRIVATE
or INTERFACE
:
target_link_libraries(B PUBLIC C)
This will ensure that B has the interface include paths that were (or will be?) added to C
, and that when an executable is build that uses B
, that C
is linked with/against it. It does not mean "build C
before B
" it means: use interface of C
to build B
.
Maybe try it like this:
A
cmake_minimum_required(VERSION 3.14)
project(A)
add_subdirectory(C)
add_subdirectory(B)
B
cmake_minimum_required(VERSION 3.14)
project(B)
add_executable(B ./source1.c)
target_link_libraries(B PUBLIC C)
C
cmake_minimum_required(VERSION 3.14)
project(C)
add_library(C SHARED sourcec.c)
target_include_directories(C PUBLIC ./) # so when compiling B it uses this include dir
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%2f55308394%2fcmake-library-not-created%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
Does this ensure that C is cmake(ed) first and then B?
No. It doesn't ensure that there even is a C
nor B
project, and it doesn't ensure that they will build at all. It just sources/includes (in a special way) C/CMakeLists.txt
and B/CMakeLists.txt
files, that's all.
add_library (C SHARED ./*c)
This is invalid, unless you have a source file named *c
. You want:
file(GLOB sources ./*c)
add_library(C SHARED $sources)
The add_library doesn't understand globulations.
pkg_check_modules(C_LIB REQUIRED C)
target_link_libraries(B C_LIB)
This is strange. You don't have a pkg-config
modules named "C" do you? You probably want:
target_link_libraries(B C)
or better try to always explicit tell PUBLIC
or PRIVATE
or INTERFACE
:
target_link_libraries(B PUBLIC C)
This will ensure that B has the interface include paths that were (or will be?) added to C
, and that when an executable is build that uses B
, that C
is linked with/against it. It does not mean "build C
before B
" it means: use interface of C
to build B
.
Maybe try it like this:
A
cmake_minimum_required(VERSION 3.14)
project(A)
add_subdirectory(C)
add_subdirectory(B)
B
cmake_minimum_required(VERSION 3.14)
project(B)
add_executable(B ./source1.c)
target_link_libraries(B PUBLIC C)
C
cmake_minimum_required(VERSION 3.14)
project(C)
add_library(C SHARED sourcec.c)
target_include_directories(C PUBLIC ./) # so when compiling B it uses this include dir
add a comment |
Does this ensure that C is cmake(ed) first and then B?
No. It doesn't ensure that there even is a C
nor B
project, and it doesn't ensure that they will build at all. It just sources/includes (in a special way) C/CMakeLists.txt
and B/CMakeLists.txt
files, that's all.
add_library (C SHARED ./*c)
This is invalid, unless you have a source file named *c
. You want:
file(GLOB sources ./*c)
add_library(C SHARED $sources)
The add_library doesn't understand globulations.
pkg_check_modules(C_LIB REQUIRED C)
target_link_libraries(B C_LIB)
This is strange. You don't have a pkg-config
modules named "C" do you? You probably want:
target_link_libraries(B C)
or better try to always explicit tell PUBLIC
or PRIVATE
or INTERFACE
:
target_link_libraries(B PUBLIC C)
This will ensure that B has the interface include paths that were (or will be?) added to C
, and that when an executable is build that uses B
, that C
is linked with/against it. It does not mean "build C
before B
" it means: use interface of C
to build B
.
Maybe try it like this:
A
cmake_minimum_required(VERSION 3.14)
project(A)
add_subdirectory(C)
add_subdirectory(B)
B
cmake_minimum_required(VERSION 3.14)
project(B)
add_executable(B ./source1.c)
target_link_libraries(B PUBLIC C)
C
cmake_minimum_required(VERSION 3.14)
project(C)
add_library(C SHARED sourcec.c)
target_include_directories(C PUBLIC ./) # so when compiling B it uses this include dir
add a comment |
Does this ensure that C is cmake(ed) first and then B?
No. It doesn't ensure that there even is a C
nor B
project, and it doesn't ensure that they will build at all. It just sources/includes (in a special way) C/CMakeLists.txt
and B/CMakeLists.txt
files, that's all.
add_library (C SHARED ./*c)
This is invalid, unless you have a source file named *c
. You want:
file(GLOB sources ./*c)
add_library(C SHARED $sources)
The add_library doesn't understand globulations.
pkg_check_modules(C_LIB REQUIRED C)
target_link_libraries(B C_LIB)
This is strange. You don't have a pkg-config
modules named "C" do you? You probably want:
target_link_libraries(B C)
or better try to always explicit tell PUBLIC
or PRIVATE
or INTERFACE
:
target_link_libraries(B PUBLIC C)
This will ensure that B has the interface include paths that were (or will be?) added to C
, and that when an executable is build that uses B
, that C
is linked with/against it. It does not mean "build C
before B
" it means: use interface of C
to build B
.
Maybe try it like this:
A
cmake_minimum_required(VERSION 3.14)
project(A)
add_subdirectory(C)
add_subdirectory(B)
B
cmake_minimum_required(VERSION 3.14)
project(B)
add_executable(B ./source1.c)
target_link_libraries(B PUBLIC C)
C
cmake_minimum_required(VERSION 3.14)
project(C)
add_library(C SHARED sourcec.c)
target_include_directories(C PUBLIC ./) # so when compiling B it uses this include dir
Does this ensure that C is cmake(ed) first and then B?
No. It doesn't ensure that there even is a C
nor B
project, and it doesn't ensure that they will build at all. It just sources/includes (in a special way) C/CMakeLists.txt
and B/CMakeLists.txt
files, that's all.
add_library (C SHARED ./*c)
This is invalid, unless you have a source file named *c
. You want:
file(GLOB sources ./*c)
add_library(C SHARED $sources)
The add_library doesn't understand globulations.
pkg_check_modules(C_LIB REQUIRED C)
target_link_libraries(B C_LIB)
This is strange. You don't have a pkg-config
modules named "C" do you? You probably want:
target_link_libraries(B C)
or better try to always explicit tell PUBLIC
or PRIVATE
or INTERFACE
:
target_link_libraries(B PUBLIC C)
This will ensure that B has the interface include paths that were (or will be?) added to C
, and that when an executable is build that uses B
, that C
is linked with/against it. It does not mean "build C
before B
" it means: use interface of C
to build B
.
Maybe try it like this:
A
cmake_minimum_required(VERSION 3.14)
project(A)
add_subdirectory(C)
add_subdirectory(B)
B
cmake_minimum_required(VERSION 3.14)
project(B)
add_executable(B ./source1.c)
target_link_libraries(B PUBLIC C)
C
cmake_minimum_required(VERSION 3.14)
project(C)
add_library(C SHARED sourcec.c)
target_include_directories(C PUBLIC ./) # so when compiling B it uses this include dir
edited Mar 23 at 3:10
answered Mar 23 at 3:01
Kamil CukKamil Cuk
14.4k2533
14.4k2533
add a comment |
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.
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%2f55308394%2fcmake-library-not-created%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