有3个文件[ mc,mh,main.c ].
MH
// m.h
int m();
Run Code Online (Sandbox Code Playgroud)
MC
// m.c
#include <stdio.h>
#include "m.h"
int m(){
printf("Hello,m!\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
main.c中
// main.c
#include "m.h"
int main(){
return m();
}
Run Code Online (Sandbox Code Playgroud)
虽然我更喜欢共享库(m.dll),但我已经制作了CMakeLists.txt
PROJECT("app1")
ADD_LIBRARY(m SHARED m.c)
ADD_EXECUTABLE(myexe main.c)
TARGET_LINK_LIBRARIES(myexe m)
Run Code Online (Sandbox Code Playgroud)
完成CMake配置并完成生成.打开app1.sln并使用Visual Studio构建,它崩溃了
LNK1104:Can't open file "Debug\m.lib"
Run Code Online (Sandbox Code Playgroud)
它只能是静态的ADD_LIBRARY().为什么它不适用于Windows?
如果我有另一个共享库(mylib.dll),我如何在main.c和CMakeLists.txt文件中调用它的函数?