这是我要运行的程序main.cpp:
#include <iostream>
#include "yaracpp/yaracpp.h"
int main() {
yaracpp::YaraDetector yara;
yara.addRules(R"(
rule example {
strings:
$s = "Hello"
condition:
$s
})");
if (yara.analyze("test_file")) {
for (const auto& rule : yara.getDetectedRules()) {
std::cout << rule << '\n';
}
}
}
当我在终端上运行此命令时,它将成功编译:
g ++ -Iinclude -Ibuild / deps / yara / src / yara / libyara / include / -Lbuild / src / -Lbuild / deps / yara / src / yara / libyara / .libs / main.cpp -lyaracpp -lyara- lpthread -lssl -lcrypto
我的CMakeLists.txt是:
cmake_minimum_required(VERSION 3.6)
project(main CXX C)
add_executable(main main.cpp)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Iinclude -Ibuild/deps/yara/src/yara/libyara/include -Lbuild/src -Lbuild/deps/yara/src/yara/libyara/.libs/")
target_link_libraries (main yaracpp yara pthread ssl crypto)
当我尝试构建它时会发生这种情况:
cmake。
-- The CXX compiler identification is GNU 7.4.0
-- The C compiler identification is GNU 7.4.0
-- 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
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/mevasu/yaracpp
制作
[ 50%] Building CXX object CMakeFiles/main.dir/main.cpp.o
/home/mevasu/yaracpp/main.cpp:2:10: fatal error: yaracpp/yaracpp.h: No such file or directory
#include "yaracpp/yaracpp.h"
^~~~~~~~~~~~~~~~~~~
compilation terminated.
CMakeFiles/main.dir/build.make:62: recipe for target 'CMakeFiles/main.dir/main.cpp.o' failed
make[2]: *** [CMakeFiles/main.dir/main.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/main.dir/all' failed
make[1]: *** [CMakeFiles/main.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
答案 0 :(得分:2)
查看输出,有以下一行:
c++: error: yaracpp/main.cpp: No such file or directory
文件是否存在?查看您的CMakeLists.txt
,该文件显示在以下命令中:
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} [..] yaracpp/main.cpp ")
^^^^^^^^^^^^^^^^
为什么在显然已经在以下行中添加yaracpp/main.cpp
的情况下将CMAKE_CXX_FLAGS
添加到add_executable(main main.cpp)
^^^^^^^^
中?
SELECT ?sitelink ?itemLabel WHERE {
?sitelink schema:about ?item;
wikibase:badge wd:Q17437798.
?sitelink schema:isPartOf <https://en.wikipedia.org/>.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } .
}
我强烈建议您在继续努力之前先学习CMake的基础知识。