我的問題:在這一刻,我dinamically鏈接libre2,但我想靜態做到這一點。我在我的電腦中安裝了庫(sudo apt-get install libre2-dev),得到了「二進制」,並將這個二進制文件「libre2.so」鏈接到我的可執行文件中。但我想要克隆存儲庫或通過git子模塊來完成此操作,然後構建此存儲庫並將其靜態鏈接到我的項目中。如何在我的項目就像一個靜態庫cmake的鏈接RE2庫
我在這裏新的,對不起我的英語不好RSS'
1)我的項目結構
- bin
- build
- external
- re2
- main.cpp
- CMakeLists.txt
- README.md
2)的CMakeLists.txt
cmake_minimum_required(VERSION 2.6)
project(simmc-agent)
# version number
set (VERSION_MAJOR 0)
set (VERSION_MINOR 0)
# cpr requires c++11
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# src : main
file (GLOB SOURCES *.cpp)
# linking res library dinamically
set(RE2_LIBRARIES -L${RE2_LIBRARY_DIR} -l libre2.so)
# src : collect functions - depend on OS
if (WIN32)
file (GLOB SOURCES ${SOURCES} src/windows/*.cpp)
else() # if(UNIX)
file (GLOB SOURCES ${SOURCES} src/linux/*.cpp)
endif()
# headers
include_directories ("include")
# test
option(PRINT_JSON "Set to ON to print json objects before sending" OFF)
message(STATUS "${PRINT_JSON}: ${${PRINT_JSON}}")
if (PRINT_JSON)
add_definitions (-DPRINT_JSON)
endif()
# compile
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin")
add_executable (agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${SOURCES})
target_link_libraries (agent-v${VERSION_MAJOR}.${VERSION_MINOR} ${RE2_LIBRARY})
3)的main.cpp
#include <iostream>
#include <re2/re2.h>
using namespace std;
using namespace re2;
int main (int argc, char **argv) {
cout << "hello world" << endl;
int matchResult;
matchResult = RE2::FullMatch("hello", "h.*o");
cout << "matchResult = " << matchResult << endl;
return 0;
}
要下載和構建RE2您可以用'ExternalProject_Add()'。您可以通過查看這兩個文件來查看您的案例:[https://github.com/project-z/mutton/blob/master/ext/re2.cmake](https://github.com/project -z /羊肉/斑點/主/ EXT/re2.cmake)和[https://github.com/petewarden/tensorflow_makefile/blob/master/tensorflow/contrib/cmake/external/re2.cmake](https:// github.com/petewarden/tensorflow_makefile/blob/master/tensorflow/contrib/cmake/external/re2.cmake),它們也使用靜態庫。 – fedepad
感謝您的幫助。當我回家時我會嘗試。之後,我會提供反饋。 –
哎...我測試了它,我有一些問題: 「這是不可能滿足-lexternal/RE2/src目錄/ RE2/OBJ/SO/libre2.so」 –