标签:style blog http color io ar 文件 2014 div
Hello.h
#pragma once void SayHello();
Hello.cpp
#include "Hello.h" #include <stdio.h> void SayHello() { printf("Hello,world!"); }
Main.cpp
#include "Hello.h" int main() { SayHello(); return 0; }
CMakeLists.txt
project(Sample3)
set(LibHello_SRC Hello.h Hello.cpp)
add_library(LibHello ${LibHello_SRC})
set(Sample3_SRC Main.cpp)
add_executable(Sample3 ${Sample3_SRC})
target_link_libraries(Sample3 LibHello)
显然,Make文件中的行2,3构成了静态库工程LibHello,行4,5构成了EXE工程Sample3,行6,使Sample3得以引用LibHello。
LibHello\CMakeLists.txt
set(LibHello_SRC Hello.h Hello.cpp)
add_library(LibHello ${LibHello_SRC})
Sample4\CMakeLists.txt
include_directories(${PROJECT_SOURCE_DIR}/LibHello)
set(Sample4_SRC Main.cpp)
add_executable(Sample4 ${Sample4_SRC})
target_link_libraries(Sample4 LibHello)
CMakeLists.txt
cmake_minimum_required(VERSION 3.0)
project(Sample4)
add_subdirectory(LibHello)
add_subdirectory(Sample4)
与Sample3不同的是,我们将LibHello与Sample4区分在了不同的目录中。
标签:style blog http color io ar 文件 2014 div
原文地址:http://www.cnblogs.com/mynamepfd/p/3970007.html