我刚刚开始使用CMake,我注意到他们同时拥有a find_package和a find_library.这让我很困惑.有人可以解释编程世界中包和库之间的区别吗?或者,在CMake的世界?
伙计们,欣赏吧!
我试图让CMake运行三个bash命令或一个bash脚本.但是,我似乎无法让它发挥作用.
bash命令是:
cd ${CMAKE_SOURCE_DIR}/dependencies/library
make
cd ${CMAKE_BINARY_DIR}
Run Code Online (Sandbox Code Playgroud)
基本上,我希望CMake在该目录中构建库,如果它尚不存在的话.
这是我试过的CMake代码:
if(NOT "${CMAKE_SOURCE_DIR}/dependencies/library/lib.o")
execute_process(COMMAND cd ${CMAKE_SOURCE_DIR}/dependencies/library)
execute_process(COMMAND make)
execute_process(COMMAND cd ${CMAKE_BINARY_DIR})
endif(NOT "${CMAKE_SOURCE_DIR}/dependencies/library/lib.o")
Run Code Online (Sandbox Code Playgroud)
但是,它没有构建任何东西.我究竟做错了什么?
此外,虽然我在这里问这个问题:是否应该包含第三个命令,移动到二进制文件夹?
谢谢!
我正在使用现有项目并清理CMake.但是,现在我对如何将CMake选项集成到实际源代码中感到有点困惑.
为了简单起见,假设我只想执行一块代码,比如说cout << "print";,example.cpp如果在CMake ENABLE_PRINT上设置了值,则执行内部代码ON.
项目目录如下所示:

使用上面的例子,我做了以下事情:
CMakeLists.txt,我补充说OPTION( ENABLE_PRINT "Enable Print" ON) Config.h文件中,我添加了#define ENABLE_PRINTConfig.h.in地处例如子项目,我加#cmakedefine ENABLE_PRINTexample.cpp,我包围了cout << "print";内部#ifdef ENABLE_PRINT和#endif进行这些更改后,项目将配置并生成就好了.但是,当我制作软件时,它会出错并且基本上告诉我,我所包围的代码块#ifdef根本没有被执行; 它被忽略了.换句话说,我采取的上述步骤除了"注释掉"我希望以ENABLE_PRINT为条件的代码块之外没有做任何事情.
那么,我将如何使这项工作?
我相信我找到了一段代码可以做到这一点,但是由于 CMake 的文档太差,我似乎再也找不到它了。
简而言之:有没有类似的东西:
if(testing_enabled)
Run Code Online (Sandbox Code Playgroud)
我可以在 CMakeLists 中使用吗?
我在这里遇到一个让我很难过的问题.所以,我必须阅读格式的内容[请阅读正文,以便更好地理解我的问题]:
TITLE
The text is actually from a file being redirected
to input stream via piping in linux bash. I cannot
use ifstream or anything other than some form of cin,
of which I believe getline to be the most useful.
etc.
Run Code Online (Sandbox Code Playgroud)
具体来说,给我带来困难的是TITLE和身体之间的空白.我似乎无法想办法解决使用getline(cin,string)的方法.
我提出的最好的:
while(inputString.size() != 0)
getline(cin,inputString);
//process string
Run Code Online (Sandbox Code Playgroud)
......用上面提到的空行抛出窗外.
伙计们,有什么想法?
谢谢!
现在,我正准备做一个家庭作业,首先要弄清楚我将在我的方法中做些什么.对于其中一个,我必须准备一个名称列表,以便添加到A1,B2,C3等形式的列表中.我现在正在测试的是通过for循环添加它们的方法.请注意,我还没有完成所有事情,我只是确保项目以正确的形式制作.我有以下代码:
list<string> L; //the list to hold the data in the form A1, B2, etc.
char C = 'A'; //the char value to hold the alphabetical letters
for(int i = 1; i <= 5; i++)
{
string peas; //a string to hold the values, they will be pushed backed here
peas.push_back(C++); //adds an alphabetical letter to the temp string, incrementing on every loop
peas.push_back(i); //is supposed to add the number that i represents to the temp string
L.push_back(peas); //the temp …Run Code Online (Sandbox Code Playgroud)