简体   繁体   English

无法在MacOS Mojave上链接C ++ 11的库

[英]Can't link libraries for C++11 on MacOS Mojave

I'm having trouble getting boost/openssl to link to my C++ project in CLion. 我无法将boost / openssl链接到CLion中的C ++项目。 I'm trying to build my program in CLion by clicking build, although I've also been trying to just manually compile with g++ but to no avail. 我试图通过单击build在CLion中构建程序,尽管我也一直尝试使用g ++手动进行编译,但无济于事。 My CMakeLists.txt looks like: 我的CMakeLists.txt看起来像:

cmake_minimum_required(VERSION 3.12)
project(FinalProject)
set(CMAKE_CXX_STANDARD 11)

# Set OpenSSL dir, this should be default on linux/mac
set(OPENSSL_INCLUDE_DIR, /usr/local/opt/openssl/bin/openssl)

# Get OpenSSL
find_package(openssl REQUIRED)

# Get cppRestSDK
find_package(cpprestsdk REQUIRED)

find_package(boost REQUIRED)



# Compile + Link
add_executable(FinalProject main.cpp)

target_link_libraries(FinalProject cpprestsdk::cpprest)

I've tried changing 我尝试改变

target_link_libraries(FinalProject cpprestsdk::cpprest)

to

target_link_libraries(FinalProject boost ssl cpprestsdk::cpprest)

and many other variations to ensure that all the dependencies I'm using get loaded (OpenSSL, cpprestsdk, and Boost) however I can't seem to get any of these to work as I keep getting various errors like: 以及许多其他变体来确保加载我正在使用的所有依赖项(OpenSSL,cpprestsdk和Boost),但是随着不断出现各种错误,我似乎无法使所有这些依赖项正常工作:

"library not found for "-lssl", "-lboost", "-lopenssl"

I installed openssl using homebrew but when I run homebrew link openssl I get: "Refusing to link macOS-provided software: openssl" and adding --force gives me the same error message. 我使用自制软件安装了openssl,但是当我运行homebrew link openssl我得到: "Refusing to link macOS-provided software: openssl"并添加--force会给我同样的错误消息。

I've created symbolic links in the paths mentioned here but to no avail. 我已经在此处提到的路径创建了符号链接,但无济于事。

Running the CMakeLists.txt with just the target_link_libraries(FinalProject cpprestsdk::cpprest) gives me: 仅使用target_link_libraries(FinalProject cpprestsdk::cpprest)运行CMakeLists.txt可得到:

Undefined symbols for architecture x86_64:
  "boost::system::detail::system_category_ncx()", referenced from:
      boost::system::system_category() in main.cpp.o
  "boost::system::detail::generic_category_ncx()", referenced from:
      boost::system::generic_category() in main.cpp.o
ld: symbol(s) not found for architecture x86_64

But I can't figure out why since it seems Boost is loading fine (I get the message "Boost Version 1.68" when I build with target_link_libraries(FinalProject PRIVATE cpprestsdk::cpprest boost) but I also get the error ld: library not found for -lboost ). 但我不知道为什么,因为Boost 似乎可以很好地加载(当我使用target_link_libraries(FinalProject PRIVATE cpprestsdk::cpprest boost)构建时,收到消息“ Boost Version 1.68”,但是我也得到了错误ld: library not found for -lboost )。

In my main.cpp (only file with code) I'm including: 在我的main.cpp(仅包含代码的文件)中,包括:

#include <iostream>
#include <string>
#include <cpprest/http_client.h>
#include <cpprest/filestream.h>
#include  "openssl/bio.h"
#include  "openssl/ssl.h"
#include  "openssl/err.h"

Anyone know what I'm missing? 有人知道我想念什么吗? I'm guessing it's something simple in my CMakeLists.txt, but not sure. 我猜这在我的CMakeLists.txt中很简单,但是不确定。 My only OpenSSL version is 1.0.2q and I'm on MacOS Mojave. 我唯一的OpenSSL版本是1.0.2q,我在MacOS Mojave上。 Running openssl in my terminal does work, so it appears to be in my PATH. 在终端中运行openssl确实可以,因此它似乎在我的PATH中。 Really at a loss here as I'm not sure what's wrong at this point. 这里真的很茫然,因为我不确定此时出了什么问题。 Any help appreciated! 任何帮助表示赞赏!

Specify that you want from boost. 指定要从增强。 Here, you need "system": 在这里,您需要“系统”:

find_package(Boost REQUIRED system)

Boost sets up variables to help after: Boost设置变量以在以下情况提供帮助:

target_link_libraries(FinalProject ssl cpprestsdk::cpprest ${Boost_SYSTEM_LIBRARY})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM