I got the following problem; I have my super library called mylib: it looks like this:
My project folder is called library...
mylib.hpp
namespace XYZ {
#ifndef LIBRARY_MYLIB_HPP
#define LIBRARY_MYLIB_HPP
int add(int, int);
#endif //LIBRARY_MYLIB_HPP
}
mylib.cpp
#include "mylib.hpp"
namespace XYZ {
int add(int a, int b) {
return a + b;
}
}
They are in the same directory.
I Build it using CMake with the following CMakeLists.txt
cmake_minimum_required(VERSION 3.6)
project(library)
add_library(library SHARED mylib.cpp)
Building Output:
[ 50%] Building CXX object CMakeFiles/library.dir/mylib.cpp.obj
[100%] Linking CXX shared library liblibrary.dll
[100%] Built target library
This works, this gives me a *.dll file like it's supposed to.
I now try to use this library in my other project
I copied the .hpp file into the project location. my main.cpp looks like this:
main.cpp
#include <iostream>
#include "mylib.hpp"
int main() {
std::cout << "Hello";
std::cout << XYZ::add(5, 7) << std::endl;
return 0;
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.6)
project(uselib)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(uselib ${SOURCE_FILES})
target_link_libraries(uselib C:/User/........./liblibrary.dll)
Building output:
[ 50%] Building CXX object CMakeFiles/uselib.dir/main.cpp.obj
[100%] Linking CXX executable uselib.exe
[100%] Built target uselib
Works. Well now to my problem.
Once I try to start it, it crashes with the following exit code:
C:\Users\......\uselib.exe
Process finished with exit code -1073741515 (0xC0000135)
When I comment the method call out, it works like a charm.
I've been stuck here for hours, any help?