Closed renhiyama closed 2 years ago
make
:
[ 12%] Built target trantor
Scanning dependencies of target drogon
[ 12%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/ConfigLoader.cc.o
[ 12%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/FiltersFunction.cc.o
[ 12%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/HttpAppFrameworkImpl.cc.o
[ 12%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/HttpClientImpl.cc.o
[ 12%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/HttpControllersRouter.cc.o
[ 12%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/HttpFileImpl.cc.o
[ 12%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/HttpRequestImpl.cc.o
[ 12%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/HttpRequestParser.cc.o
[ 12%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/HttpResponseImpl.cc.o
[ 12%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/HttpServer.cc.o
[ 12%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/HttpSimpleControllersRouter.cc.o
[ 12%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/ListenerManager.cc.o
[ 12%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/MultiPart.cc.o
[ 12%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/StaticFileRouter.cc.o
[ 14%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/Utilities.cc.o
[ 14%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/WebSocketClientImpl.cc.o
[ 14%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/WebSocketConnectionImpl.cc.o
[ 14%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/WebsocketControllersRouter.cc.o
[ 16%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/SharedLibManager.cc.o
[ 16%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/orm_lib/src/postgresql_impl/PgConnection.cc.o
[ 16%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/lib/src/RedisClientManagerSkipped.cc.o
[ 18%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/orm_lib/src/DbClient.cc.o
[ 18%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/orm_lib/src/DbClientImpl.cc.o
[ 18%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/orm_lib/src/DbClientLockFree.cc.o
[ 18%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/orm_lib/src/DbConnection.cc.o
[ 20%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/orm_lib/src/SqlBinder.cc.o
[ 20%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/orm_lib/src/TransactionImpl.cc.o
[ 20%] Building CXX object _deps/drogon-build/CMakeFiles/drogon.dir/orm_lib/src/DbClientManager.cc.o
[ 22%] Linking CXX static library ../../lib/libdrogon.a
[ 40%] Built target drogon
[ 42%] Linking CXX executable bin/rdl.server
/usr/bin/ld: cannot find -lJsoncpp_lib
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/rdl.server.dir/build.make:115: bin/rdl.server] Error 1
make[1]: *** [CMakeFiles/Makefile2:628: CMakeFiles/rdl.server.dir/all] Error 2
make: *** [Makefile:171: all] Error 2
At first I tried to use the portion of code you provided to see if it was failures in your CMakeLists. txt, but it wasn't and yet I received a similar error in MSVC 2019, I dug into the code as it seemed strange to me that it would fail to link a headers only library, it failed and failed and I even started to doubt if I was creating a library of only headers correctly, until I decided to copy the headers and move them to the root directory of the project that I had created as an example, link them to the executable and surprise failure with the same error, with this I supposed that it was not an error when creating the library but an error in the definitions of the methods, I reviewed the code and I found the root of the problem: You are trying to link a library as a header-only library when it is not.
Here is my solution:
CMAKE_MINIMUM_REQUIRED(VERSION 3.14)
PROJECT(Help)
SET(CMAKE_CXX_STANDARD 17)
INCLUDE(CPM.cmake)
CPMAddPackage(
NAME Jsoncpp
URL https://github.com/open-source-parsers/jsoncpp/archive/refs/tags/1.9.5.tar.gz
VERSION 1.9.5
)
get_target_property(JSON_INC_PATH jsoncpp_lib INTERFACE_INCLUDE_DIRECTORIES)
include_directories(${JSON_INC_PATH})
ADD_EXECUTABLE(Help main.cpp)
TARGET_LINK_LIBRARIES(Help PUBLIC jsoncpp_static)
#include "json/json.h"
#include <iostream>
int main() {
Json::Value root;
Json::Value data;
constexpr bool shouldUseOldWay = false;
root["action"] = "run";
data["number"] = 1;
root["data"] = data;
if (shouldUseOldWay) {
Json::FastWriter writer;
const std::string json_file = writer.write(root);
std::cout << json_file << std::endl;
} else {
Json::StreamWriterBuilder builder;
const std::string json_file = Json::writeString(builder, root);
std::cout << json_file << std::endl;
}
return EXIT_SUCCESS;
}
C:\Users\andre\CLionProjects\Help\cmake-build-debug\bin\Help.exe
{
"action" : "run",
"data" :
{
"number" : 1
}
}
In fact, if you check the code you will find a different name of the library depending on whether it is compiled as an object of type SHARED or STATIC, so you have to be careful with that when working with your executables or other libraries.
The library even has the definition of the library for a type OBJECT which will be very useful to avoid all this code amalgamation.
Oh thanks!
If it worked correctly and you are satisfied with the solution you can close the issue, thank you very much @renhiyama
Oh ok sure!
I have wasted 3 days trying every method possible, reading all the docs online, but still the cmake crashes... Heres my cmake list:
output for
cmake