CMake error when try to add external library












0















I need to add an external library in my project.
Here is the project structure:



/- src/
- my source files here…
|- dist/
|- FLTK
|- lib/
|- libfltk.a
|- libfltk_forms.a
|- FL
|- build/
|- main.cpp


Here is my CMakeLists.txt



cmake_minimum_required(VERSION 2.8)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++17")

find_library(LibFltk ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/libfltk.a)
find_library(LibFltk_Forms ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/libfltk_forms.a)

if(APPLE)
find_library(COCOA Cocoa)
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK)

add_executable(${CMAKE_CURRENT_SOURCE_DIR}/build/main ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)

target_link_libraries(${CMAKE_CURRENT_SOURCE_DIR}/build/main ${LibFltk} ${COCOA})


Error message:



    CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LibFltk
linked by target "keyplay" in directory /Users/coder/Desktop/sandbox/keyplay


-- Configuring incomplete, errors occurred!



When I try to compile my project from terminal it works perfect.
This is how I do it:



g++ -std=c++17 -c main.cpp -I dist/FLTK 
&& g++ main.o -o main -L dist/FLTK/lib -lfltk_forms
-lfltk_images
-lfltk
-lfltk_gl
-framework Cocoa
&& ./main


What is wrong in my CMakeLists.txt?



Thanks.










share|improve this question


















  • 1





    Have you tried (cmake.org/cmake/help/v3.0/command/find_library.html) find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)?

    – Matthieu Brucher
    Nov 25 '18 at 12:03











  • Thanks Matthieu, it helped me!

    – Levon Sarkisov
    Nov 25 '18 at 12:11











  • Did it solve the issue? If yes, I'll make it an answer.

    – Matthieu Brucher
    Nov 25 '18 at 12:12











  • Yes, Matthieu, it was the correct answer.

    – Levon Sarkisov
    Nov 25 '18 at 12:13


















0















I need to add an external library in my project.
Here is the project structure:



/- src/
- my source files here…
|- dist/
|- FLTK
|- lib/
|- libfltk.a
|- libfltk_forms.a
|- FL
|- build/
|- main.cpp


Here is my CMakeLists.txt



cmake_minimum_required(VERSION 2.8)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++17")

find_library(LibFltk ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/libfltk.a)
find_library(LibFltk_Forms ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/libfltk_forms.a)

if(APPLE)
find_library(COCOA Cocoa)
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK)

add_executable(${CMAKE_CURRENT_SOURCE_DIR}/build/main ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)

target_link_libraries(${CMAKE_CURRENT_SOURCE_DIR}/build/main ${LibFltk} ${COCOA})


Error message:



    CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LibFltk
linked by target "keyplay" in directory /Users/coder/Desktop/sandbox/keyplay


-- Configuring incomplete, errors occurred!



When I try to compile my project from terminal it works perfect.
This is how I do it:



g++ -std=c++17 -c main.cpp -I dist/FLTK 
&& g++ main.o -o main -L dist/FLTK/lib -lfltk_forms
-lfltk_images
-lfltk
-lfltk_gl
-framework Cocoa
&& ./main


What is wrong in my CMakeLists.txt?



Thanks.










share|improve this question


















  • 1





    Have you tried (cmake.org/cmake/help/v3.0/command/find_library.html) find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)?

    – Matthieu Brucher
    Nov 25 '18 at 12:03











  • Thanks Matthieu, it helped me!

    – Levon Sarkisov
    Nov 25 '18 at 12:11











  • Did it solve the issue? If yes, I'll make it an answer.

    – Matthieu Brucher
    Nov 25 '18 at 12:12











  • Yes, Matthieu, it was the correct answer.

    – Levon Sarkisov
    Nov 25 '18 at 12:13
















0












0








0








I need to add an external library in my project.
Here is the project structure:



/- src/
- my source files here…
|- dist/
|- FLTK
|- lib/
|- libfltk.a
|- libfltk_forms.a
|- FL
|- build/
|- main.cpp


Here is my CMakeLists.txt



cmake_minimum_required(VERSION 2.8)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++17")

find_library(LibFltk ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/libfltk.a)
find_library(LibFltk_Forms ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/libfltk_forms.a)

if(APPLE)
find_library(COCOA Cocoa)
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK)

add_executable(${CMAKE_CURRENT_SOURCE_DIR}/build/main ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)

target_link_libraries(${CMAKE_CURRENT_SOURCE_DIR}/build/main ${LibFltk} ${COCOA})


Error message:



    CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LibFltk
linked by target "keyplay" in directory /Users/coder/Desktop/sandbox/keyplay


-- Configuring incomplete, errors occurred!



When I try to compile my project from terminal it works perfect.
This is how I do it:



g++ -std=c++17 -c main.cpp -I dist/FLTK 
&& g++ main.o -o main -L dist/FLTK/lib -lfltk_forms
-lfltk_images
-lfltk
-lfltk_gl
-framework Cocoa
&& ./main


What is wrong in my CMakeLists.txt?



Thanks.










share|improve this question














I need to add an external library in my project.
Here is the project structure:



/- src/
- my source files here…
|- dist/
|- FLTK
|- lib/
|- libfltk.a
|- libfltk_forms.a
|- FL
|- build/
|- main.cpp


Here is my CMakeLists.txt



cmake_minimum_required(VERSION 2.8)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++17")

find_library(LibFltk ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/libfltk.a)
find_library(LibFltk_Forms ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/libfltk_forms.a)

if(APPLE)
find_library(COCOA Cocoa)
endif()

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK)

add_executable(${CMAKE_CURRENT_SOURCE_DIR}/build/main ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)

target_link_libraries(${CMAKE_CURRENT_SOURCE_DIR}/build/main ${LibFltk} ${COCOA})


Error message:



    CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LibFltk
linked by target "keyplay" in directory /Users/coder/Desktop/sandbox/keyplay


-- Configuring incomplete, errors occurred!



When I try to compile my project from terminal it works perfect.
This is how I do it:



g++ -std=c++17 -c main.cpp -I dist/FLTK 
&& g++ main.o -o main -L dist/FLTK/lib -lfltk_forms
-lfltk_images
-lfltk
-lfltk_gl
-framework Cocoa
&& ./main


What is wrong in my CMakeLists.txt?



Thanks.







c++ cmake fltk






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 11:48









Levon SarkisovLevon Sarkisov

1818




1818








  • 1





    Have you tried (cmake.org/cmake/help/v3.0/command/find_library.html) find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)?

    – Matthieu Brucher
    Nov 25 '18 at 12:03











  • Thanks Matthieu, it helped me!

    – Levon Sarkisov
    Nov 25 '18 at 12:11











  • Did it solve the issue? If yes, I'll make it an answer.

    – Matthieu Brucher
    Nov 25 '18 at 12:12











  • Yes, Matthieu, it was the correct answer.

    – Levon Sarkisov
    Nov 25 '18 at 12:13
















  • 1





    Have you tried (cmake.org/cmake/help/v3.0/command/find_library.html) find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)?

    – Matthieu Brucher
    Nov 25 '18 at 12:03











  • Thanks Matthieu, it helped me!

    – Levon Sarkisov
    Nov 25 '18 at 12:11











  • Did it solve the issue? If yes, I'll make it an answer.

    – Matthieu Brucher
    Nov 25 '18 at 12:12











  • Yes, Matthieu, it was the correct answer.

    – Levon Sarkisov
    Nov 25 '18 at 12:13










1




1





Have you tried (cmake.org/cmake/help/v3.0/command/find_library.html) find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)?

– Matthieu Brucher
Nov 25 '18 at 12:03





Have you tried (cmake.org/cmake/help/v3.0/command/find_library.html) find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)?

– Matthieu Brucher
Nov 25 '18 at 12:03













Thanks Matthieu, it helped me!

– Levon Sarkisov
Nov 25 '18 at 12:11





Thanks Matthieu, it helped me!

– Levon Sarkisov
Nov 25 '18 at 12:11













Did it solve the issue? If yes, I'll make it an answer.

– Matthieu Brucher
Nov 25 '18 at 12:12





Did it solve the issue? If yes, I'll make it an answer.

– Matthieu Brucher
Nov 25 '18 at 12:12













Yes, Matthieu, it was the correct answer.

– Levon Sarkisov
Nov 25 '18 at 12:13







Yes, Matthieu, it was the correct answer.

– Levon Sarkisov
Nov 25 '18 at 12:13














2 Answers
2






active

oldest

votes


















1














The find_library function expects the second argument to be the filename you are targeting (http://www.cmake.org/cmake/help/v3.0/command/find_library.html), and you need to specify the paths where to look as additional arguments:



find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)
find_library(LibFltk_Forms libfltk_forms.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)





share|improve this answer

































    0














    Thanks to @Matthieu Brucher. Here is correct config:



    cmake_minimum_required(VERSION 2.8)

    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++17")
    include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK)

    add_executable(keyplay ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)

    find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)

    if(APPLE)
    find_library(COCOA Cocoa)
    endif()

    target_link_libraries(keyplay ${LibFltk} ${COCOA})





    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%2f53467121%2fcmake-error-when-try-to-add-external-library%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      The find_library function expects the second argument to be the filename you are targeting (http://www.cmake.org/cmake/help/v3.0/command/find_library.html), and you need to specify the paths where to look as additional arguments:



      find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)
      find_library(LibFltk_Forms libfltk_forms.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)





      share|improve this answer






























        1














        The find_library function expects the second argument to be the filename you are targeting (http://www.cmake.org/cmake/help/v3.0/command/find_library.html), and you need to specify the paths where to look as additional arguments:



        find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)
        find_library(LibFltk_Forms libfltk_forms.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)





        share|improve this answer




























          1












          1








          1







          The find_library function expects the second argument to be the filename you are targeting (http://www.cmake.org/cmake/help/v3.0/command/find_library.html), and you need to specify the paths where to look as additional arguments:



          find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)
          find_library(LibFltk_Forms libfltk_forms.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)





          share|improve this answer















          The find_library function expects the second argument to be the filename you are targeting (http://www.cmake.org/cmake/help/v3.0/command/find_library.html), and you need to specify the paths where to look as additional arguments:



          find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)
          find_library(LibFltk_Forms libfltk_forms.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 25 '18 at 12:31

























          answered Nov 25 '18 at 12:13









          Matthieu BrucherMatthieu Brucher

          16.5k32143




          16.5k32143

























              0














              Thanks to @Matthieu Brucher. Here is correct config:



              cmake_minimum_required(VERSION 2.8)

              set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++17")
              include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK)

              add_executable(keyplay ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)

              find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)

              if(APPLE)
              find_library(COCOA Cocoa)
              endif()

              target_link_libraries(keyplay ${LibFltk} ${COCOA})





              share|improve this answer




























                0














                Thanks to @Matthieu Brucher. Here is correct config:



                cmake_minimum_required(VERSION 2.8)

                set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++17")
                include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK)

                add_executable(keyplay ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)

                find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)

                if(APPLE)
                find_library(COCOA Cocoa)
                endif()

                target_link_libraries(keyplay ${LibFltk} ${COCOA})





                share|improve this answer


























                  0












                  0








                  0







                  Thanks to @Matthieu Brucher. Here is correct config:



                  cmake_minimum_required(VERSION 2.8)

                  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++17")
                  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK)

                  add_executable(keyplay ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)

                  find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)

                  if(APPLE)
                  find_library(COCOA Cocoa)
                  endif()

                  target_link_libraries(keyplay ${LibFltk} ${COCOA})





                  share|improve this answer













                  Thanks to @Matthieu Brucher. Here is correct config:



                  cmake_minimum_required(VERSION 2.8)

                  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++17")
                  include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK)

                  add_executable(keyplay ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp)

                  find_library(LibFltk libfltk.a PATHS ${CMAKE_CURRENT_SOURCE_DIR}/dist/FLTK/lib/)

                  if(APPLE)
                  find_library(COCOA Cocoa)
                  endif()

                  target_link_libraries(keyplay ${LibFltk} ${COCOA})






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 25 '18 at 12:12









                  Levon SarkisovLevon Sarkisov

                  1818




                  1818






























                      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%2f53467121%2fcmake-error-when-try-to-add-external-library%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

                      Wiesbaden

                      Marschland

                      Dieringhausen