当我尝试使用这个 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"
我已经查看了有关使用 cmake 安装 stb_image 的堆栈溢出的所有相关问题,但这些解决方案都没有为我工作。我究竟做错了什么 ?
我已经用 GCC 编译了我的代码,它工作正常,但现在我需要使用我的 IDE 的调试器,为此我必须用 cmake 编译它。