[CMake] Write CMakeLists.txt for this C++ program
dexter810
meghna.vasudeva at gmail.com
Wed Jun 19 06:42:29 EDT 2019
This is the program I want to run, 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';
}
}
}
When I run this command on the terminal it compiles successfully:
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
*Approach 1:*
My CMakeLists.txt is:
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)
But this was not able to link it properly and threw errors that it cannot
find "yaracpp/yaracpp.h". The references for writing CMakeLists.txt like
this were:
https://stackoverflow.com/questions/43136418/how-to-add-l-ell-compiler-flag-in-cmake
https://stackoverflow.com/questions/53879422/how-to-set-g-compile-options-in-clion?answertab=oldest#tab-top
--
Sent from: http://cmake.3232098.n2.nabble.com/
More information about the CMake
mailing list