ADD_EXECUTABLE(hello main.cpp)
ADD_LIBRARY(haha SHARED haha.cpp)
ADD_LIBRARY(haha_static STATIC haha.cpp)
SET_TARGET_PROPERTIES(haha_static PROPERTIES OUTPUT_NAME "hello")
#SET_TARGET_PROPERTIES(haha PROPERTIES VERSION 1.2 SOVERSION 1) #在linux下的动态库是有版本号的,windows下的动态库则没有版本号这个概念
SET(EXECUTABLE_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/lib")
SET(LIBRARY_OUTPUT_PATH "${PROJECT_SOURCE_DIR}/lib")
#include "haha.h"
using namespace std;
void haha()
{
cout<<"haha"<<endl;
}
#ifndef HAHA_H
#define HAHA_H
#include
void haha();
#endif
#include
using namespace std;
int main()
{
cout<<"hello world"<<endl;
return 0;
}
cmake …
devenv.com Project.sln /Build “Debug|x64”
SHARED,动态库
STATIC,静态库
ADD_LIBRARY(libname [SHARED|STATIC|MODULE]
[EXCLUDE_FROM_ALL]
source1 source2 ... sourceN)
ADD_LIBRARY(haha SHARED haha.cpp)
ADD_LIBRARY(haha_static STATIC haha.cpp)
SET_TARGET_PROPERTIES(haha_static PROPERTIES OUTPUT_NAME "hello")
SET_TARGET_PROPERTIES(hello PROPERTIES VERSION 1.2 SOVERSION 1)
VERSION 指代动态库版本,SOVERSION 指代 API 版本
SET_TARGET_PROPERTIES(haha PROPERTIES VERSION 1.2 SOVERSION 1)
下一篇文章讲解