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;








0















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?










share|improve this question






























    0















    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?










    share|improve this question


























      0












      0








      0








      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?










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 23 at 2:32









      avariant

      1,81831221




      1,81831221










      asked Mar 22 at 22:07









      UnniboyUnniboy

      12




      12






















          1 Answer
          1






          active

          oldest

          votes


















          0















          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





          share|improve this answer

























            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
            );



            );













            draft saved

            draft discarded


















            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









            0















            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





            share|improve this answer





























              0















              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





              share|improve this answer



























                0












                0








                0








                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





                share|improve this answer
















                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






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 23 at 3:10

























                answered Mar 23 at 3:01









                Kamil CukKamil Cuk

                14.4k2533




                14.4k2533





























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현