【问题标题】:How can I edit a CMAKELIST.txt file on CLION to take LDFLAGS and CPPFLAGS如何在 CLION 上编辑 CMAKELIST.txt 文件以获取 LDFLAGS 和 CPPFLAGS
【发布时间】:2020-04-01 09:45:07
【问题描述】:

我在 MAC Mojave 上安装了 openssl1.1.1d,并在我的 .bash_profile 中添加了以下内容:

export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

我一直试图让这段代码在 CLION 上编译,但我一直收到错误。

cmake_minimum_required(VERSION 3.15)
project(untitled3 C)
SET (CMAKE_SHARED_LINKER_FLAGS ${CMAKE_SHARED_LINKER_FLAGS_INIT} $ENV{LDFLAGS})
set(CMAKE_C_STANDARD 99)
set(/usr/local/opt/openssl@1.1/bin/openssl)
include_directories(${I})
link_libraries(ssl)
link_libraries(crypto)
set(SOURCE_FILES mywebsock.c)
add_executable(untitled3 mywebsock.c)

错误信息:

fatal error: 'openssl/ssl.h' file not found
#include <openssl/ssl.h> 1 error generated.

我尝试像这样在我的终端上编译:

gcc -Wall -o mywebsock mywebsock.c -lssl -lcrypto -pthread

我收到了这个错误。

Undefined symbols for architecture x86_64:
  "_OPENSSL_init_ssl", referenced from:
      _init_openssl in mywebsock -8aaca3.o
ld: symbol(s) not found for architecture x86_64

我认为这是因为我的链接错误。请问,有人可以帮帮我吗?我整夜都在试图弄清楚这一点。我已经安装并重新安装了 openssl。我检查了几个帖子,但我似乎无法以某种方式正确。

【问题讨论】:

  • set(/usr/local/opt/openssl@1.1/bin/openssl) 行中 - 您似乎忘记为要设置的变量指定一个名称

标签: macos cmake openssl clion


【解决方案1】:

不要在这个过程中迷路,而只是load all those configuration settings from the pkg-config (.pc) file it installed for you

list(PREPEND CMAKE_PREFIX_PATH /usr/local/opt/openssl@1.1)
find_package(PkgConfig REQUIRED) 
pkg_check_modules(Ssl IMPORTED_TARGET openssl)

add_executable(untitled3 mywebsock.c)
target_link_libraries(untitled3 PkgConfig::Ssl)

IMPORTED_TARGET 位将创建一个包含所有必要设置的目标,以包括 OpenSSL。

【讨论】:

    猜你喜欢
    • 2013-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    • 2023-03-16
    • 2018-02-23
    • 1970-01-01
    相关资源
    最近更新 更多