在MacOS上使用stb_image库时,无法使用cmake构建C项目

问题描述

当我尝试使用此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)

我收到以下错误

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对其进行编译。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)