Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[macOS] I can't compile an project that includes Drogon. #1161

Closed
0rangeFox opened this issue Jan 19, 2022 · 6 comments
Closed

[macOS] I can't compile an project that includes Drogon. #1161

0rangeFox opened this issue Jan 19, 2022 · 6 comments
Assignees

Comments

@0rangeFox
Copy link
Contributor

0rangeFox commented Jan 19, 2022

Basically, tells me I don't have this or this. I will provide errors and some debug to check if I missing something. Using the Drogon version 1.7.4 as git module and homebrew formula from my fork.

Without Drogon homebrew formula:
Basically I just added the Drogon as module of my git project, cmake without errors and can't compile.

CMake:

cmake_minimum_required(VERSION 3.21)

project(WebService CXX)

message(STATUS)
message(STATUS "System: ${CMAKE_SYSTEM}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Paths:")
message(STATUS " - ${PROJECT_SOURCE_DIR}")
message(STATUS " - ${CMAKE_INSTALL_PREFIX}")
message(STATUS " - ${CMAKE_SOURCE_DIR}")
message(STATUS " - ${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS)
message(STATUS "Compiler:")
message(STATUS " - ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS " - ${CMAKE_CXX_COMPILER}")
message(STATUS)
message(STATUS "CMake:")
message(STATUS " - ${CMAKE_VERSION}")
message(STATUS " - ${CMAKE_COMMAND}")
message(STATUS " - ${CMAKE_TOOLCHAIN_FILE}")
message(STATUS " - ${CMAKE_GENERATOR}")
message(STATUS " - ${CMAKE_BUILD_TOOL}")
message(STATUS)

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS src/*.c src/*.cc src/*.cpp src/*.hpp src/*.h)

set(CMAKE_CXX_STANDARD 14)

include(CheckIncludeFileCXX)

check_include_file_cxx(any HAS_ANY)
check_include_file_cxx(string_view HAS_STRING_VIEW)
check_include_file_cxx(coroutine HAS_COROUTINE)

if (NOT "${CMAKE_CXX_STANDARD}" STREQUAL "")
    # Do nothing
elseif (HAS_ANY AND HAS_STRING_VIEW AND SUPPORT_COROUTINE)
    set(CMAKE_CXX_STANDARD 20)
elseif (HAS_ANY AND HAS_STRING_VIEW)
    set(CMAKE_CXX_STANDARD 17)
else ()
    set(CMAKE_CXX_STANDARD 14)
endif ()

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_executable(${PROJECT_NAME} ${SOURCES})

# ##############################################################################

add_subdirectory(libraries/drogon)
target_link_libraries(${PROJECT_NAME} PRIVATE drogon)

# ##############################################################################

if (CMAKE_CXX_STANDARD LESS 17)
    # With C++14, use boost to support any, string_view and filesystem
    message(STATUS "use c++14")
    find_package(Boost 1.61.0 REQUIRED)
    target_link_libraries(${PROJECT_NAME} PUBLIC Boost::boost)
elseif (CMAKE_CXX_STANDARD LESS 20)
    message(STATUS "use c++17")
else ()
    message(STATUS "use c++20")
endif ()

aux_source_directory(controllers CTL_SRC)
aux_source_directory(filters FILTER_SRC)
aux_source_directory(plugins PLUGIN_SRC)
aux_source_directory(models MODEL_SRC)
aux_source_directory(utils UTILS_SRC)

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/models)
target_sources(${PROJECT_NAME} PRIVATE ${CTL_SRC} ${FILTER_SRC} ${PLUGIN_SRC} ${MODEL_SRC} ${UTILS_SRC})

Error:

====================[ Build | WebService | Debug ]========================
"/Users/0rangefox/Library/Application Support/JetBrains/Toolbox/apps/CLion/ch-0/213.6461.75/CLion.app/Contents/bin/cmake/mac/bin/cmake" --build /Users/0rangefox/Projects/CLion/WebService/cmake-build-debug --target WebService
[0/2] Re-checking globbed directories...
[1/1] Linking CXX executable WebService
FAILED: WebService 
: && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -g -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/WebService.dir/src/main.cpp.o -o WebService  libraries/drogon/libdrogon.a  libraries/drogon/trantor/libtrantor.a  /opt/homebrew/lib/libcares.dylib  -ldl  /opt/homebrew/lib/libboost_filesystem-mt.dylib  /opt/homebrew/lib/libboost_system-mt.dylib  -ljsoncpp  /opt/homebrew/lib/libuuid.dylib  /opt/homebrew/lib/libbrotlidec.dylib  /opt/homebrew/lib/libbrotlienc.dylib  /opt/homebrew/lib/libbrotlicommon.dylib  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/libsqlite3.tbd  /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/lib/libz.tbd && :
ld: library not found for -ljsoncpp
clang: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

Now, with Drogon homebrew formula:
Without Drogon as module, and CMake give error.

CMake:

cmake_minimum_required(VERSION 3.21)

project(WebService CXX)

message(STATUS)
message(STATUS "System: ${CMAKE_SYSTEM}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Paths:")
message(STATUS " - ${PROJECT_SOURCE_DIR}")
message(STATUS " - ${CMAKE_INSTALL_PREFIX}")
message(STATUS " - ${CMAKE_SOURCE_DIR}")
message(STATUS " - ${CMAKE_CURRENT_SOURCE_DIR}")
message(STATUS)
message(STATUS "Compiler:")
message(STATUS " - ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS " - ${CMAKE_CXX_COMPILER}")
message(STATUS)
message(STATUS "CMake:")
message(STATUS " - ${CMAKE_VERSION}")
message(STATUS " - ${CMAKE_COMMAND}")
message(STATUS " - ${CMAKE_TOOLCHAIN_FILE}")
message(STATUS " - ${CMAKE_GENERATOR}")
message(STATUS " - ${CMAKE_BUILD_TOOL}")
message(STATUS)

file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS src/*.c src/*.cc src/*.cpp src/*.hpp src/*.h)

set(CMAKE_CXX_STANDARD 14)

include(CheckIncludeFileCXX)

check_include_file_cxx(any HAS_ANY)
check_include_file_cxx(string_view HAS_STRING_VIEW)
check_include_file_cxx(coroutine HAS_COROUTINE)

if (NOT "${CMAKE_CXX_STANDARD}" STREQUAL "")
    # Do nothing
elseif (HAS_ANY AND HAS_STRING_VIEW AND SUPPORT_COROUTINE)
    set(CMAKE_CXX_STANDARD 20)
elseif (HAS_ANY AND HAS_STRING_VIEW)
    set(CMAKE_CXX_STANDARD 17)
else ()
    set(CMAKE_CXX_STANDARD 14)
endif ()

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

add_executable(${PROJECT_NAME} ${SOURCES})

# ##############################################################################

find_package(Drogon CONFIG REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE Drogon::Drogon)

# ##############################################################################

if (CMAKE_CXX_STANDARD LESS 17)
    # With C++14, use boost to support any, string_view and filesystem
    message(STATUS "use c++14")
    find_package(Boost 1.61.0 REQUIRED)
    target_link_libraries(${PROJECT_NAME} PUBLIC Boost::boost)
elseif (CMAKE_CXX_STANDARD LESS 20)
    message(STATUS "use c++17")
else ()
    message(STATUS "use c++20")
endif ()

aux_source_directory(controllers CTL_SRC)
aux_source_directory(filters FILTER_SRC)
aux_source_directory(plugins PLUGIN_SRC)
aux_source_directory(models MODEL_SRC)
aux_source_directory(utils UTILS_SRC)

target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/models)
target_sources(${PROJECT_NAME} PRIVATE ${CTL_SRC} ${FILTER_SRC} ${PLUGIN_SRC} ${MODEL_SRC} ${UTILS_SRC})

Error:

"/Users/0rangefox/Library/Application Support/JetBrains/Toolbox/apps/CLion/ch-0/213.6461.75/CLion.app/Contents/bin/cmake/mac/bin/cmake" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=/Users/0rangefox/Library/Application Support/JetBrains/Toolbox/apps/CLion/ch-0/213.6461.75/CLion.app/Contents/bin/ninja/mac/ninja" -G Ninja /Users/0rangefox/Projects/CLion/WebService
-- 
-- System: Darwin-21.2.0
-- Build type: Debug
-- Paths:
--  - /Users/0rangefox/Projects/CLion/WebService
--  - /usr/local
--  - /Users/0rangefox/Projects/CLion/WebService
--  - /Users/0rangefox/Projects/CLion/WebService
-- 
-- Compiler:
--  - AppleClang 13.0.0.13000029
--  - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- 
-- CMake:
--  - 3.21.1
--  - /Users/0rangefox/Library/Application Support/JetBrains/Toolbox/apps/CLion/ch-0/213.6461.75/CLion.app/Contents/bin/cmake/mac/bin/cmake
--  - 
--  - Ninja
--  - /Users/0rangefox/Library/Application Support/JetBrains/Toolbox/apps/CLion/ch-0/213.6461.75/CLion.app/Contents/bin/ninja/mac/ninja
-- 
-- jsoncpp verson:1.9.5
CMake Error at /Users/0rangefox/Library/Application Support/JetBrains/Toolbox/apps/CLion/ch-0/213.6461.75/CLion.app/Contents/bin/cmake/mac/share/cmake-3.21/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
  system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY
  OPENSSL_INCLUDE_DIR)
Call Stack (most recent call first):
  /Users/0rangefox/Library/Application Support/JetBrains/Toolbox/apps/CLion/ch-0/213.6461.75/CLion.app/Contents/bin/cmake/mac/share/cmake-3.21/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /Users/0rangefox/Library/Application Support/JetBrains/Toolbox/apps/CLion/ch-0/213.6461.75/CLion.app/Contents/bin/cmake/mac/share/cmake-3.21/Modules/FindOpenSSL.cmake:574 (find_package_handle_standard_args)
  /Users/0rangefox/Library/Application Support/JetBrains/Toolbox/apps/CLion/ch-0/213.6461.75/CLion.app/Contents/bin/cmake/mac/share/cmake-3.21/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/homebrew/lib/cmake/Trantor/TrantorConfig.cmake:38 (find_dependency)
  /Users/0rangefox/Library/Application Support/JetBrains/Toolbox/apps/CLion/ch-0/213.6461.75/CLion.app/Contents/bin/cmake/mac/share/cmake-3.21/Modules/CMakeFindDependencyMacro.cmake:47 (find_package)
  /opt/homebrew/lib/cmake/Drogon/DrogonConfig.cmake:40 (find_dependency)
  CMakeLists.txt:53 (find_package)


-- Configuring incomplete, errors occurred!
See also "/Users/0rangefox/Projects/CLion/WebService/cmake-build-debug/CMakeFiles/CMakeOutput.log".
See also "/Users/0rangefox/Projects/CLion/WebService/cmake-build-debug/CMakeFiles/CMakeError.log".

[Finished]

Brew formula list:
image

I think that's all, any more information if needed, please let me know, thanks.

@an-tao
Copy link
Member

an-tao commented Jan 20, 2022

Did you install the libjsoncpp via brew or source code?

@0rangeFox
Copy link
Contributor Author

Yes, I installed from this jsoncpp formula.

@rbugajewski
Copy link
Collaborator

I would suggest you use the Homebrew formula and just fix the OpenSSL error.

@rbugajewski
Copy link
Collaborator

And maybe you can verify if you have OpenSSL installed at the right place:

/usr/local/Cellar/openssl@1.1 $ ls
1.1.1m

@0rangeFox
Copy link
Contributor Author

I think this is it, I noticed on some sites that it was like this. Homebrew path for Intel-based CPU is like what you said and for M1 is on /opt/homebrew/Cellar/<formula>/.... But anyways, I forgot to mention I already fixed it. The problem I had was, I had done CMake before I had the dependency formulas or the Drogon formula installed. So the solution in this case would be to completely delete the "build" or "cmake-build-debug" folder, install the necessary dependencies and then build CMake. If you want to install the dependencies, I suggest you install through the Drogon formula which is simpler and the operation is the same and with this formula you already have the Drogon Controller already built in, that is, you can use the dg_ctl or drogon_ctl commands.

@0rangeFox
Copy link
Contributor Author

0rangeFox commented Jan 22, 2022

Another tip, some here may have problems about OpenSSL that they can't compile because CMake can't find the directory or it goes wrong. To solve this, it is simple, you just have to execute the command brew info openssl@1.1, and detailed information about that formula will appear, all you have to do is look in the section that says "For compilers to find openssl@1.1 you may need to set:", and copy the export that ends with "lib". And then, run the following command on build folder of project: cmake -DOPENSSL_ROOT_DIR=<export without /lib> -DOPENSSL_LIBRARIES=<export with /lib> ..
An example command in my case: cmake -DOPENSSL_ROOT_DIR=/opt/homebrew/opt/openssl@1.1 -DOPENSSL_LIBRARIES=/opt/homebrew/opt/openssl@1.1/lib ..

@rbugajewski rbugajewski self-assigned this Feb 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants