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
在MacOS上使用stb_映像库时,无法使用cmake生成C项目_C_Cmake_Stb Image - Fatal编程技术网

在MacOS上使用stb_映像库时,无法使用cmake生成C项目

在MacOS上使用stb_映像库时,无法使用cmake生成C项目,c,cmake,stb-image,C,Cmake,Stb Image,当我尝试使用此cmake文件构建项目时: cmake_minimum_required(VERSION 3.17) project(C_Projects C) set(CMAKE_C_STANDARD 11) link_directories(${CMAKE_SOURCE_DIR}/stb_image) include_directories(${CMAKE_SOURCE_DIR}_DIR}/stb_image) add_library(stb_image stb_image/stb_im

当我尝试使用此cmake文件构建项目时:

cmake_minimum_required(VERSION 3.17)
project(C_Projects C)

set(CMAKE_C_STANDARD 11)

link_directories(${CMAKE_SOURCE_DIR}/stb_image)
include_directories(${CMAKE_SOURCE_DIR}_DIR}/stb_image)

add_library(stb_image stb_image/stb_image.h)
add_library(stb_image_write stb_image/stb_image_write.h)
SET_TARGET_PROPERTIES(stb_image PROPERTIES LINKER_LANGUAGE C)
SET_TARGET_PROPERTIES(stb_image_write PROPERTIES LINKER_LANGUAGE C)

add_executable(C_Projects main.c)

target_link_libraries(C_Projects stb_image stb_image_write)
我得到的cmake错误为:

ar: ar: no archive members specifiedno archive members specified

usage:  ar -d [-TLsv] archive file ...
usage:  ar -d [-TLsv] archive file ...
    ar -m [-TLsv] archive file ...
    ar -m [-TLsv] archive file ...
    ar -m [-abiTLsv] position archive file ...
    ar -m [-abiTLsv] position archive file ...
    ar -p [-TLsv] archive [file ...]
    ar -p [-TLsv] archive [file ...]
    ar -q [-cTLsv] archive file ...
    ar -q [-cTLsv] archive file ...
    ar -r [-cuTLsv] archive file ...
    ar -r [-cuTLsv] archive file ...
    ar -r [-abciuTLsv] position archive file ...
    ar -r [-abciuTLsv] position archive file ...
    ar -t [-TLsv] archive [file ...]
    ar -t [-TLsv] archive [file ...]
    ar -x [-ouTLsv] archive [file ...]
    ar -x [-ouTLsv] archive [file ...]
make[3]: make[3]: *** [libstb_image.a] Error 1*** [libstb_image_write.a] Error 1

make[2]: *** [CMakeFiles/stb_image.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....
make[2]: *** [CMakeFiles/stb_image_write.dir/all] Error 2
make[1]: *** [CMakeFiles/C_Projects.dir/rule] Error 2
make: *** [C_Projects] Error 2
这里是我在源文件中包含库的地方

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

#define STB_IMAGE_IMPLEMENTATION

#include "stb_image/stb_image.h"

#define STB_IMAGE_WRITE_IMPLEMENTATION

#include "stb_image/stb_image_write.h"
#包括
#包括
#包括
#包括
#定义机顶盒映像的实现
#包括“机顶盒图像/机顶盒图像.h”
#定义机顶盒映像写入实现
#包括“机顶盒映像/机顶盒映像写入.h”
我已经研究了有关使用cmake安装stb_映像的堆栈溢出的所有相关问题,这些解决方案都不适合我。我做错了什么


我已经用GCC编译了我的代码,它工作得很好,但是现在我需要使用IDE的调试器,为此我必须用cmake编译它。

请提供
make VERBOSE=1
的完整输出。错误不是特定于stb映像的。您试图仅从标题(没有源)创建库,这是错误的。没有源文件的库称为仅头库,CMake为其提供了特殊类型的目标:接口。有关更多信息,请参阅重复问题。