I am currently trying to set up the opendnp3 C++ library as a static library. I've built the solution following their build guide for Windows and have been able to generate several .lib files which I assume to be the static libraries.
In a completely separate folder, I have the following files under the following folder structure:
C:/Development/C++/opendnp3/lib/ # .lib files are contained in this directory
C:/Development/pybexample/
--> CMakeLists.txt
--> src/
--> test.cpp
I have the CMakeLists.txt configured as follows:
cmake_minimum_required(VERSION 2.8)
project(pybexample)
set(SOURCE_FILES src/test.cpp)
add_library(opendnp3 STATIC IMPORTED)
set_target_properties(opendnp3 PROPERTIES IMPORTED_LOCATION C:/Development/C++/opendnp3/lib/opendnp3.lib)
add_executable(pybexample ${SOURCE_FILES})
target_link_libraries(pybexample opendnp3)
Within test.cpp, I am simply calling:
#include <iostream>
#include "opendnp3/LogLevels.h"
using namespace std;
int main(void) {
cout << "Hello world!" << endl;
system("pause");
}
However, when I try to build test.cpp, I receive an error indicating: "Cannot open include file: 'opendnp3/LogLevels.h': No such file or directory". I feel like there must be something pretty basic that I've missed but I'm pretty new to using static libraries and with CMake so I can't seem to figure it out. Would anyone be able to help give some pointers as to why my include is failing?
Turns out this was caused by two problems.
The first problem was that I needed to add a line to my
CMakeLists.txtthat would add the header files for opendnp3 to my project. This was accomplished by addinginclude_directories(<path_to_headers>)before theadd_executable(pybexample ${SOURCE_FILES})line.However, in doing this, it also became clear that there was a second problem: I hadn't built the library properly as it didn't generate any headers with the library. Turns out I had overlooked the instructions to run the INSTALL project. After setting CMAKE_INSTALL_PREFIX and running the INSTALL project, the library and headers were generated and ready for use.