如何重新编译源文件每次使用cmake 2.8.2在单构建的c ++ 11和c ++ 98的共享库创建? [英] How to recompile source file every time while using cmake 2.8.2 in single build for c++11 and c++98 for shared library creation?

查看:446
本文介绍了如何重新编译源文件每次使用cmake 2.8.2在单构建的c ++ 11和c ++ 98的共享库创建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目目录结构:

 

Common
MyFolder
++我的3个源文件和标题

3到4个共享库。 Lib1 使用c ++ 98编译,其他使用c ++ 11编译。标志添加在位于根目录的CmakeList.txt中。
我需要我的3个源文件编译为 Lib1 和其他Libs以及。但是在这里发生了什么是编译器首先编译我的源文件lib使用c + + 11,然后它试图使用相同的.o文件为Lib1以及。所以使用c ++ 11生成的.o文件在使用c ++ 98编译库时会抛出异常。



那么如何在CmakeList .txt,这样编译器而不是试图使用相同的.o文件将为Lib1(c ++ 98编译库)再次编译源文件



有任何标志



这里的标志没有被覆盖不同的共享库,但实际上是相同的目标文件通过make文件正在用于不同的标志

解决方案

这是对makefile和 code>通常工作。



大多数用户认为 make 执行增量构建非常重要。 / p>

makefiles的通常方法是执行 make clean ,它应该删除任何已创建的二进制文件和对象文件。



然而,有时我编写cmake脚本,使用glob遍布源目录来汇编项目。 (这意味着,它说只需抓住 / src 文件夹中的所有 *。cpp 文件,他们。)makefile不能检查目录中的什么文件,所以make build将在我添加一个新文件后被破坏, make clean 将无法修复它 - - 整个makefile需要通过 cmake 重新生成。



通常我所做的是写一个简单的bash脚本,命名为 rebuild.sh 或某事,

 #! bin / bash 
rm -rf build
mkdir build
cd build
cmake ..
make -j3
./tests

我把它放在我的仓库的根目录下,添加 / build 到我的 .gitignore 。我调用,当我想做一个完全重建 - 它nukes的构建目录,所以它的万无一失。当我想要一个增量重建,我只需在 / build 目录中再次键入 make



如果使用 travis-ci rebuild.sh c>以便持续集成。


I have a project directory structure of:

Root
  Source
    Common
      MyFolder
      ++ My 3 source files and header 

When I am building my project it generates 3 to 4 shared libraries. Lib1 compiled using c++98 and others using c++11. Flags are added in CmakeList.txt which is at root. I need my 3 source files to be compiled for Lib1 and for other Libs as as well. but here what happens is compiler is first compiling my source file for lib using c++11 and then it is trying to use same .o file for Lib1 as well. So for .o file which is generated using c++11 is throwing exception when same is used for c++98 compiled library.

So how do write this in CmakeList.txt such that compiler rather than trying to use same .o file will compile source file again for Lib1(c++98 compiled library)

Is there any flag I can specify so that it won't take precompiled .o file and will compile it again ?

Here flags are not being overridden for different shared libraries but actually same object file by make file is being used for different flags

解决方案

This is sort of counter to how makefiles and cmake usually work.

Most users consider it really important that make performs an incremental build.

The usual way with makefiles is to do make clean which is supposed to remove any binaries and object files that were created.

However, sometimes I write cmake scripts that use globbing over the source directory to assemble the project. (That means, it says "just grab all *.cpp files in the /src folder and make an executable from them".) A makefile cannot check what files in a directory, so the make build will be broken after I add a new file, and make clean won't fix it -- the whole makefile will need to be regenerated by cmake.

Usually what I do is, I write a simple bash script, named rebuild.sh or something,

#!/bin/bash
rm -rf build
mkdir build
cd build
cmake ..
make -j3
./tests

And I put that in the root of my repository, and add /build to my .gitignore. I call that when I want to do a full rebuild -- it nukes the build directory, so its foolproof. When I want an incremental rebuild, I just type make again in the /build directory.

The rebuild.sh script can also serve a double purpose if you use travis-ci for continuous integration.

这篇关于如何重新编译源文件每次使用cmake 2.8.2在单构建的c ++ 11和c ++ 98的共享库创建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆