1

I want to use this library c++ library in my code on external directory, which I have build with cmake (I'm new with it), as the compiling tutorial explain. After this, what files (or makefiles) do I'm suppose to add to my directory to do things like this is my code

#include "rpc/server.h"

I saw something about importing static libraries that would have to add a CMakeLists.txt to my directory and compile my main code with something as

g++ -static main.cc -L<librpc.a directory> -lrpc -o main

But getting this:

fatal error: rpc/server.h: No such file or directory compilation terminated.

I have searched the web about these procedures but I'm not having sucess on this. Could someone help

Adelson Araújo
  • 332
  • 1
  • 5
  • 17

1 Answers1

0

First you need to add the rpc library to the project as an imported library, and subsequently you must specify target properties such as the imported location and the include directories.

add_library(rpc SHARED IMPORTED)
set_target_properties(rcp
    PROPERTIES
    IMPORTED_LOCATION "${rpc_LIBRARIES}"
    INCLUDE_DIRECTORIES "${rpc_INCLUDES}"
)

After you've successfully added the rpc library to the project, just add rpc as a target to your executable.

add_executable(your_test_program main.cpp)
target_link_libraries(your_test_program PRIVATE rpc )
RAM
  • 2,257
  • 2
  • 19
  • 41