Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't link from CMake #808

Open
thcrt opened this issue Dec 11, 2023 · 1 comment
Open

Can't link from CMake #808

thcrt opened this issue Dec 11, 2023 · 1 comment

Comments

@thcrt
Copy link

thcrt commented Dec 11, 2023

I'm a huge beginner to C and CMake, so apologies if I've missed anything obvious.

I try to link cJSON like this:

# CMakeLists.txt

cmake_minimum_required(VERSION 3.28)
project(myproj VERSION 0.0.1
                 LANGUAGES C
)

find_package( CURL REQUIRED )
find_package( cJSON REQUIRED )
add_executable(myproj myproj.c)
target_link_libraries( myproj CURL::libcurl )
target_link_libraries( myproj cJSON::cjson )

It won't build, despite having it installed:

theo@dev ~/myproj (main)> cmake -B build
-- Configuring done (0.1s)
CMake Error at CMakeLists.txt:11 (target_link_libraries):
  Target "myproj" links to:

    cJSON::cjson

  but the target was not found.  Possible reasons include:

    * There is a typo in the target name.
    * A find_package call is missing for an IMPORTED target.
    * An ALIAS target is missing.



-- Generating done (0.0s)
CMake Generate step failed.  Build files cannot be regenerated correctly.

theo@dev ~/myproj (main) [1]> ls /usr/lib/cmake/cJSON
cJSONConfig.cmake  cJSONConfigVersion.cmake  cjson-noconfig.cmake  cjson.cmake  cjson_utils-noconfig.cmake  cjson_utils.cmake
@zeerd
Copy link

zeerd commented Dec 26, 2023

The Config.cmake of cJSON has no namespace. Which means you need to use cjson but not cJSON::cjson.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants