Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何链接<;bsd/stdio.h>;在cmake中使用funopen()_Linux_Cmake_Stdio_Bsd - Fatal编程技术网

Linux 如何链接<;bsd/stdio.h>;在cmake中使用funopen()

Linux 如何链接<;bsd/stdio.h>;在cmake中使用funopen(),linux,cmake,stdio,bsd,Linux,Cmake,Stdio,Bsd,我正在使用Ubuntu,我想使用funopen(),但是这个函数只在BSD系统中使用。所以我安装了libbsd sudo apt-get install libbsd-dev 之后,我可以在这个头文件中包含并看到funopen()。但无法编译。 我尝试在CMakeLists.txt中使用此选项,但没有使用: 查找包(bsd) 我想参数不是bsd,我该怎么做 [更新]按照@Alu建议执行,仍然不起作用: cmake_minimum_required(VERSION 3.3) project(my

我正在使用Ubuntu,我想使用
funopen()
,但是这个函数只在BSD系统中使用。所以我安装了libbsd

sudo apt-get install libbsd-dev
之后,我可以在这个头文件中包含并看到
funopen()
。但无法编译。 我尝试在CMakeLists.txt中使用此选项,但没有使用:

查找包(bsd)

我想参数不是bsd,我该怎么做

[更新]按照@Alu建议执行,仍然不起作用:

cmake_minimum_required(VERSION 3.3)
project(myProject)

set(SOURCE_FILES main.c)
set(DIR_TO_LIB_HEADERS, /usr/include/bsd)
set(DIR_TO_BSD_LIB_FILE, /usr/lib/x86_64-linux-gnu/libbsd.so)
include_directories(${DIR_TO_LIB_HEADERS})
add_executable(myProject ${SOURCE_FILES})
target_link_libraries(myProject ${DIR_TO_BSD_LIB_FILE})
有误:

undefined reference to `funopen'

我认为cmake没有提供“查找”bsd库的模块。 您可以查看并尝试了解cmake查找机制是如何工作的

但我建议在您的cmake文件中明确包含目录。 我想你必须用类似的东西

set(DIR_TO_LIB_HEADERS /usr/include/bsd)
set(DIR_TO_BSD_LIB_FILE /usr/lib/i386-linux-gnu/libbsd.so) #or /usr/lib/x86_64-linux-gnu/libbsd.so on 64 bit OS
include_directories(${DIR_TO_LIB_HEADERS})
target_link_libraries(${PROJECT_NAME} ${DIR_TO_BSD_LIB_FILE})
您可以找到lib的文件列表

32位操作系统:

set(DIR_TO_BSD_LIB_FILE /usr/lib/i386-linux-gnu/libbsd.so)
target_link_libraries(${PROJECT_NAME} ${DIR_TO_BSD_LIB_FILE})
64位操作系统:

set(DIR_TO_BSD_LIB_FILE /usr/lib/x86_64-linux-gnu/libbsd.so)
target_link_libraries(${PROJECT_NAME} ${DIR_TO_BSD_LIB_FILE})

很抱歉,我找不到/usr/lib/i386 linux gnu/libbsd。因此,我需要安装任何lib吗?我已经安装了libbsd dev?请尝试在您的系统上查找文件。也许你已经安装了x64版本,也许我找到了旧版本的Lib-bsd。谷歌安装libbsdI时将安装哪些文件找到了它,但仍然无法运行,我已经更新了问题最后我发现了你的答案问题,删除了集合中的逗号。谢谢:)错误表明编译器找不到方法的定义。因此,要么头文件没有定义方法,要么将引用错误的头文件。尝试包括
bsd/stdio.h