简体   繁体   English

带有Json-C的体系结构x86_64的未定义符号

[英]Undefined symbols for architecture x86_64 with Json-C

Basically it's my first stack overflow question, so I am sorry for any inaccuracies/stupid questions here + I have tried for 3 days to solve my problem using all other answers people gave on similar questions, but either way I don't know Cmake enough or I am doing something wrong from the very beginning. 基本上这是我的第一个堆栈溢出问题,所以我很抱歉这里有任何不准确/愚蠢的问题+我已经尝试了3天使用人们对类似问题给出的所有其他答案来解决我的问题,但无论哪种方式我都不知道Cmake或者我从一开始就做错了什么。

I've installed Json-c through Homebrew ( brew install json-c ). 我通过Homebrew安装了Json-c( brew install json-c )。 I am using Clion on macOS which uses Cmake. 我在使用Cmake的macOS上使用Clion。 I have modified my CmakeLists: 我修改了我的CmakeLists:

cmake_minimum_required(VERSION 3.10) 
project(Project C)

set(CMAKE_C_STANDARD 99) 
INCLUDE_DIRECTORIES(/usr/local/Cellar/json-c/0.13.1/include/json-c) 
LINK_DIRECTORIES(/usr/local/Cellar/json-c/0.13.1/lib)


add_executable(Project main.c functions.c functions.h exp_functions.c exp_functions.h) 
TARGET_LINK_LIBRARIES(Project)

but I am not sure how to set arguments for TARGET_LINK_LIBRARIES. 但我不确定如何为TARGET_LINK_LIBRARIES设置参数。

When I am trying to build the project it gives me this: 当我尝试构建项目时,它给了我:

 Undefined symbols for architecture x86_64:


    "_json_object_new_double", referenced from:
          _GenerateJson in functions.c.o
      "_json_object_new_object", referenced from:
          _GenerateJson in functions.c.o
      "_json_object_new_string", referenced from:
          _GenerateJson in functions.c.o
      "_json_object_object_add", referenced from:
          _GenerateJson in functions.c.o
      "_json_object_to_json_string", referenced from:
          _GenerateJson in functions.c.o
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

From what I have found on the web, someone had similar problem ( https://github.com/json-c/json-c/issues/235 ), but after I have installed the package through Brew, I don't have any "json-c" files/folders in /usr/local/lib. 从我在网上找到的,有人有类似的问题( https://github.com/json-c/json-c/issues/235 ),但在我通过Brew安装包后,我没有/ usr / local / lib中的任何“json-c”文件/文件夹。 There's only "json-c" alias in usr/local/include to brew directory. usr / local / include中只有“json-c”别名为brew目录。

I have tried to install json-c using instructions that are provided on repository site ( https://github.com/json-c/json-c ), but after that I had no clue how to set CmakeLists.txt to make the project work 我曾尝试使用存储库站点( https://github.com/json-c/json-c )上提供的说明安装json-c,但之后我不知道如何设置CmakeLists.txt来制作项目工作

What am I doing wrong. 我究竟做错了什么。 I am fresh at programming at all + I don't know much of the cmake and how macOS/Homebrew manages files when I am installing new packages through git clone . 我很喜欢编程+我不太了解cmake以及当我通过git clone安装新软件包时macOS / Homebrew如何管理文件。

You are missing something like 你错过了类似的东西

LDFLAGS+= -ljson-c

to link with the library. 链接到图书馆。 It was in the setup instructions for CMake in their README. 它是在自述文件中的CMake的设置说明中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM