使用netcdf-c的架构x86_64的未定义符号

时间:2016-11-08 23:47:04

标签: compilation cmake netcdf clion

我目前正在使用netcdf-c库进行项目。我用Homebrew安装了它。我写了一个小脚本来编写.NC文件。我正在使用Mac

当我使用make main在CLion中编译它时,输出如下:

make main
cc     main.c   -o main
Undefined symbols for architecture x86_64:
"_nc_close", referenced from:
  _main in main-f43ab9.o
"_nc_get_var_int", referenced from:
  _main in main-f43ab9.o
"_nc_inq_varid", referenced from:
  _main in main-f43ab9.o
"_nc_open", referenced from:
  _main in main-f43ab9.o
"_nc_strerror", referenced from:
  _main in main-f43ab9.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [main] Error 1

这是我的Cmakelists.txt的内容:

cmake_minimum_required(VERSION 3.6)
project(hello)

INCLUDE_DIRECTORIES(/usr/local/include)
LINK_DIRECTORIES(/usr/local/lib)

set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} /usr/local/lib)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} cc -stdlib=lnetcdf -Wall -Werror main.c")

INCLUDE_DIRECTORIES(/usr/local/include)
LINK_DIRECTORIES(/usr/local/lib)

set(SOURCE_FILES main.c)
add_executable(hello ${SOURCE_FILES})

尽管如此,我还是可以使用终端执行我的代码并输入:

cc -lnetcdf main.c

有人能告诉我问题在哪里吗?

由于

0 个答案:

没有答案