undefined reference to `Json::Value::Value`/CMake find wrong gcc version

编译时报错现象:

undefined reference to `Json::Value::Value

根据这个链接的说法,you have jsoncpp compiled with a different C++ ABI than you link against. The easiest solution is to use exactly the same compiler-version to build both library and executable. jsoncpp使用了其他的c++ ABI编译,而不是现在正在使用的c++ ABI 版本。

查看cmake的输出,发现cmake使用的是另外一个c++,而不是默认的c++。也就是cmake没有找到正确的c++版本,原因是(链接):cmake默认使用cc而不是gcc,如果默认的c++路径中没有cc的话,cmake就会去找其他的路径,找到后,c++也会使用这个路径下面的,从而导致默认的c++没有被使用,解决方法是制定cmake使用的cc为gcc,见下面的参数

essentially CMake uses cc and c++ wherever they are off the $PATH, which is not always the same as gcc or g++.

Specifying these compilers fixes the version shown by CMake:

cmake -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ ..

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值