首页IT科技Ubuntu cmake 不装openssl(UBuntu CMake工程配置基础)

Ubuntu cmake 不装openssl(UBuntu CMake工程配置基础)

时间2025-06-20 19:38:35分类IT科技浏览4246
导读:分类: C++ 2011-09-09 10:38 1024人阅读 评论(1 收藏 举报 目录(? [+] install...

分类:

C++

2011-09-09 10:38 1024人阅读 评论(1) 收藏 举报

目录(?)[+]

install CMake HelloWorld工程 外部构建 支持gdb调试

install CMake

我用CMake并不关注它的跨平台特性            ,因为我只专注于64位 Linux C++ server领域            。

sudo apt-get install cmake

chenshu@chenshu-ubuntu:~$ cmake —version

cmake version 2.8.3

HelloWorld工程

mkdir -p examples/helloworld

cd examples/helloworld

创建main.cpp 文件                  ,代码如下:

[cpp] view plaincopyprint?
#include<stdio.h> intmain() { printf("HelloWorldfromMain!\n"); return0; }
#include <stdio.h> int main() { printf("Hello World from Main!\n"); return 0; }

创建CMakeLists.txt文件     ,配置如下:

[plain] view plaincopyprint?
PROJECT(HELLOWorld) SET(SRC_LISTmain.cpp) MESSAGE(STATUS"ThisisBINARYdir"${HELLO_BINARY_DIR}) MESSAGE(STATUS"ThisisSOURCEdir"${HELLO_SOURCE_DIR}) ADD_EXECUTABLE(hello${SRC_LIST})
PROJECT (HELLOWorld) SET(SRC_LIST main.cpp) MESSAGE(STATUS "This is BINARY dir " ${HELLO_BINARY_DIR}) MESSAGE(STATUS "This is SOURCE dir "${HELLO_SOURCE_DIR}) ADD_EXECUTABLE(hello ${SRC_LIST})

在同目录下         ,运行cmake .

chenshu@chenshu-ubuntu:~/Ubuntu One/c++/cmake/examples/helloworld$ cmake .

— The C compiler identification is GNU

— The CXX compiler identification is GNU

— Check for working C compiler: /usr/bin/gcc

— Check for working C compiler: /usr/bin/gcc — works

— Detecting C compiler ABI info

— Detecting C compiler ABI info - done

— Check for working CXX compiler: /usr/bin/c++

— Check for working CXX compiler: /usr/bin/c++ — works

— Detecting CXX compiler ABI info

— Detecting CXX compiler ABI info - done

— This is BINARY dir /home/chenshu/Ubuntu One/c++/cmake/examples/helloworld

— This is SOURCE dir /home/chenshu/Ubuntu One/c++/cmake/examples/helloworld

— Configuring done

— Generating done

— Build files have been written to: /home/chenshu/Ubuntu One/c++/cmake/examples/helloworld

Makefile以及其他一些文件被cmake生成了                  。执行make命令,hello二进制文件被编译出来     。运行./hello,可以看到结果         。

Hello World from Main!

make VERBOSE=1 可以看到详细的编译过程                  。

make clean 就可以清理工程

外部构建

HelloWorld采用内部构建                  ,cmake产生的代码和自己的源代码文件在同一个目录        ,非常不好        。因此需要采用cmake的外部构建方式      。

创建helloworld2目录

这次创建一个src目录存放源代码      ,doc目录存放项目文档                  ,

CMakeLists.txt需要出现在项目根目录和src目录中                  。

项目根目录下的内容如下:

project (HelloWorld2)

add_subdirectory(src bin)

src目录下内容如下:

add_executable(hello2 main.cpp)

创建一个build目录

cd build

cmake ..

make

build/bin下会找到hello2可执行文件           。

支持gdb调试

在src/CMakeLists.txt文件中添加一行: set(CMAKE_BUILD_TYPE Debug)

声明:本站所有文章           ,如无特殊说明或标注   ,均为本站原创发布   。任何个人或组织                  ,在未征得本站同意时              ,禁止复制            、盗用                 、采集      、发布本站内容到任何网站         、书籍等各类媒体平台                  。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理              。

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
vue组件入门(最好的Vue组件库之Vuetify的入坑指南(持续更新中))