我正在尝试使静态库耦合(包括其他静态库的标头和代码)。
我的第一个不需要任何东西的静态库
test.c和test.h
//test.c
#ifndef TEST_H
#define TEST_H
#include "test.h"
int somenum(int x){
return x*x;
}
#endif
// test.h file
#ifndef TEST_H
#define TEST_H
#define object 1
int somenum(int x);
#endif
这样可以很好地创建并创建testlib1.a
// prj name is testlib1 , cmakelists.txt file (not included all)
ADD_LIBRARY(${PRJ_NAME} STATIC ${SOURCE_FILES})
TARGET_LINK_LIBRARIES(${PRJ_NAME} libFreeRTOS)# libFreeRTOS)
哪个好。然后我有test2.c和test2.h,其中的标头包含“ test.h”
//test2.h
#ifndef TEST2_H
#define TEST2_H
#define objecte 1
#include "test.h"
#endif
//test2.c
#ifndef TEST_H
#define TEST_H
#include "test2.h"
int somenum2(int x){
return test(x);
}
#endif
在libtest2.a创建静态库的同时,我应该做些什么(我假设)链接libtest1.a。但是要么我找不到库,要么不知道如何用cmake正确地做(或者用cmake不可能?),我看到了一些关于UNIX上ar命令的建议(我正在研究)
#find_library(teste NAMES "libtest2" PATHS "/home/ugurkan/Desktop/Untitled" NO_DEFAULT_PATH)
#message(${teste})
#set(CMAKE_C_FLAGS "-mcpu=cortex-m4 -std=gnu11 -g3 -DUSE_HAL_DRIVER -DDEBUG -DSTM32F407xx -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage")
#ADD_LIBRARY(testbir STATIC IMPORTED GLOBAL)
#SET(testbir_path ../${PROJECT_SOURCE_DIR})
#set_property(${PRJ_NAME} testbir PROPERTY IMPORTED_LOCATION "/home/ugurkan/Desktop/Untitled/libtest1.a")
#message(testbir)
#set_target_properties(${PRJ_NAME} testbir PROPERTIES IMPORTED_LOCATION "/home/ugurkan/Desktop/Untitled/libtest1.a")
#message(${PRJ_NAME})
ADD_LIBRARY(${PRJ_NAME} STATIC ${SOURCE_FILES})
TARGET_LINK_LIBRARIES(${PRJ_NAME} testiki)
在test2.c和test2.h的cmakelist.txt上测试过的命令(可能会给出提示)