如何在CLION上编辑CMAKELIST.txt文件以采用LDFLAGS和CPPFLAGS

我在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。我检查了几篇文章,但似乎无法正确解决。

chenxcl12345 回答:如何在CLION上编辑CMAKELIST.txt文件以采用LDFLAGS和CPPFLAGS

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在内的所有必要设置的目标。

本文链接:https://www.f2er.com/2956397.html

大家都在问