windows下CMake使用图文手册 Part 4
例子4:链接静态库(.lib)
例子3里面我们构建了date.lib, 这个例子里我们调用这个库。
前提:
date.h的头文件在
E:\Playground\CMakeExamples\DateLib\include
date.lib或date.dll文件在
E:\Playground\CMakeExamples\lib
CMakeLists.txt里需要用到这两个地址。
文件结构:
E:.
│ CMakeLists.txt
│
├─build
└─src
main.cpp
main.cpp:
// main.cpp
#include <iostream>
#include "date.h"
int main()
{
Date date(2016,05,05);
std::cout<<"Year:"<<date.getYear()<<" Month:"<<date.getMonth()
<<" day:"<<date.getDay()<<std::endl;
}
CMakeLists.txt内容
cmake_minimum_required(VERSION 3.5.2)
project(usingLib_test)
set(userLibDir "E:/Playground/CMakeExamples/lib")
#For the static library:
set (PROJECT_LINK_LIBS date)
link_directories(${userLibDir})
#Bring the headers, such as Date.h into the project
set( dateLibInclude "E:/Playground/CMakeExamples/DateLib/include/")
include_directories(${dateLibInclude})
#The file(GLOB...) allows for wildcard additions:
file(GLOB SOURCES "src/*.cpp")
add_executable(testUsingLib ${SOURCES})
target_link_libraries(testUsingLib ${PROJECT_LINK_LIBS} )
Tips: 注意引用变量时需要用${}而非$().
include_directories命令的帮助:
include_directories
-------------------
Add include directories to the build.
::
include_directories([AFTER|BEFORE] [SYSTEM] dir1 [dir2 ...])
Add the given directories to those the compiler uses to search for
include files. Relative paths are interpreted as relative to the
current source directory.
The include directories are added to the ``INCLUDE_DIRECTORIES``
directory property for the current ``CMakeLists`` file. They are also
added to the ``INCLUDE_DIRECTORIES`` target property for each
target in the current ``CMakeLists`` file. The target property values
are the ones used by the generators.
By default the directories specified are appended onto the current list of
directories. This default behavior can be changed by setting
``CMAKE_INCLUDE_DIRECTORIES_BEFORE`` to ``ON``. By using
``AFTER`` or ``BEFORE`` explicitly, you can select between appending and
prepending, independent of the default.
If the ``SYSTEM`` option is given, the compiler will be told the
directories are meant as system include directories on some platforms.
Signalling this setting might achieve effects such as the compiler
skipping warnings, or these fixed-install system files not being
considered in dependency calculations - see compiler docs.
Arguments to ``include_directories`` may use "generator expressions" with
the syntax "$<...>". See the ``cmake-generator-expressions(7)``
manual for available expressions. See the ``cmake-buildsystem(7)``
manual for more on defining buildsystem properties.
link_directories
----------------
Specify directories in which the linker will look for libraries.
::
link_directories(directory1 directory2 ...)
Specify the paths in which the linker should search for libraries.
The command will apply only to targets created after it is called.
Relative paths given to this command are interpreted as relative to
the current source directory, see ``CMP0015``.
Note that this command is rarely necessary. Library locations
returned by ``find_package()`` and ``find_library()`` are
absolute paths. Pass these absolute library file paths directly to the
``target_link_libraries()`` command. CMake will ensure the linker finds
them.
windows下CMake使用图文手册 Part 4的更多相关文章
- windows下CMake使用图文手册 Part 3
例子3: 构建动态库(.dll) 静态库(.lib) 采用和例子2一样的文件,但删除了main.cpp E:. │ CMakeLists.txt │ ...
- windows下CMake使用图文手册 Part 1
维基百科介绍“CMake是个开源的跨平台自动化建构系统,它用配置文件控制建构过程(build process)的方式和Unix的Make相似,只是CMake的配置文件取名为CMakeLists.txt ...
- windows下CMake使用图文手册 Part 2
例子2:有目录的项目 我现在有个文件夹ProjectDate,有如下文件结构 E:. │ CMakeLists.txt │ ├─include │ Date.h │ └─src ...
- Windows下CMake编译安装OpenCV
Windows下CMake编译安装OpenCV 这是一个面向新手的在windows上运进opencv, helloword的教程. 在这里我们使用vs2019来编译opencv, 并运行一个hello ...
- 在Windows下编译ffmpeg完全手册
本文的内容几乎全部来自于FFmpeg on Windows,但是由于国内的网络封锁,很难访问这个域名下的内容,因此我一方面按照我自己的理解和实践做了翻译,另一方面也是为了能提供一个方便的参考方法. 注 ...
- [转]在Windows下编译ffmpeg完全手册
本文的内容几乎全部来自于FFmpeg on Windows,但是由于国内的网络封锁,很难访问这个域名下的内容,因此我一方面按照我自己的理解和实践做了翻译,另一方面也是为了能提供一个方便的参考方法. 注 ...
- windows下安装Mysql—图文详解
mysql安装过程及注意事项: 1.1. 下载: 我下载的是64位系统的zip包: 下载地址:https://dev.mysql.com/downloads/mysql/ 下载zip的包: 下载后解压 ...
- windows下安装Mysql(图文详解)
博客园 | 首页 | 新随笔 | 联系 | 订阅 | 管理 mysql安装过程及注意事项: 1.1. 下载: 我下载的是64位系统的zip包: 下载地址:https://dev.mysql.com ...
- Windows下C++/Fortran调用.exe可执行文件
目录 软件环境 Windows下CMake编译配置 设置项目的generator Command Line CMake GUI PreLoad.cmake 设置make 示例程序 CMake 设置Fo ...
随机推荐
- python 自学 1 day
#!/usr/bin/env python #coding = utf-8 age_of_oldby = 56 user = "fyt" word = "fyt" ...
- js jquery实时计算输入字符
在项目中需要倒还可以输入多少字符
- [读书笔记]自动装箱的陷阱以及==与equals
先看一段代码,来自周志明的<深入理解Java虚拟机>. Integer a = 1; Integer b = 2; Integer c = 3; Integer d = 3; Intege ...
- 关于word excel 等的信息隐藏技术
简单的word 信息隐藏技术分为两种 一 利用word自带的功能对信息进行隐藏,即选中要隐藏的文字 单击右键 选择字体 给隐藏选项打勾即可 这种信息隐藏比较简单 找到的方式为单机文件——找 ...
- 暑假前的flag
暑假到了,为了简便新开了一个博客,供暑假刷体放一些题解,玩acm1年多了,cf还是蓝名,真是菜的一笔,明年就大三了,马上就要毕业了,然而还是啥也不会,兼职和智障没什么两样,当初大一吹的牛逼说要成为学校 ...
- Angular.JS + Require.JS + angular-async-loader 来实现异步加载 angular 模块
传统的 angular 应用不支持异步加载模块,必须在 module 启动的时候,所有模块必须预加载进来. 通过使用 angular-async-loader 库,我们可以使用 requirejs 等 ...
- MR跑百分27不动引发的问题
今天跑MR跑到百分27就卡住不懂,查看JOB history也没看到MR,日志也没看到异常.50030端口页面不知道为什么打不开.由于MR里面设计Hbase就去查了下hbase的表.发现hbase l ...
- IIC
IIC多主从,双向传输,只有两根线:一根数据,一根时钟,时钟必须由主机发出控制.初始化时主机把SCL和SDA的电平都拉高,然后在SCL保持高电平时SDA拉低形成一个开始信号,紧接着开始信号就开始发送要 ...
- linux find命令
Linux中find常见用法示例 ·find path -option [ -print ] [ -exec -ok command ] {} \; find命令的参数 ...
- c#选择文件文件夹
C#选择文件 OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.InitialDirectory = "C://&qu ...