如何向cmake添加CFLAGS以在本地查找依赖项?

huangapple go评论82阅读模式
英文:

How do you add CFLAGS to cmake to look for dependencies locally?

问题

I'm trying to install C++ web framework, drogon, which requires following steps to install.

cd $WORK_PATH
git clone https://github.com/drogonframework/drogon
cd drogon
git submodule update --init
mkdir build
cd build
cmake ..
make && sudo make install

To install locally, I added the following command option:
cmake --install-prefix=$HOME/local.

However, the make process ended up like this:

/bin/ld: ../trantor/libtrantor.a(OpenSSLProvider.cc.o): in function `OpenSSLProvider::processHandshake()`:
OpenSSLProvider.cc:(.text._ZN15OpenSSLProvider16processHandshakeEv[_ZN15OpenSSLProvider16processHandshakeEv]+0x504): undefined reference to `SSL_get1_peer_certificate`
/bin/ld: ../trantor/libtrantor.a(openssl.cc.o): in function `trantor::utils::md5(void const*, unsigned long)`:
openssl.cc:(.text+0x35): undefined reference to `EVP_MD_fetch`
/bin/ld: openssl.cc:(.text+0xa1): undefined reference to `EVP_MD_free`
/bin/ld: ../trantor/libtrantor.a(openssl.cc.o): in function `trantor::utils::sha1(void const*, unsigned long)`:
openssl.cc:(.text+0xfc): undefined reference to `EVP_MD_fetch`
/bin/ld: openssl.cc:(.text+0x168): undefined reference to `EVP_MD_free`
/bin/ld: ../trantor/libtrantor.a(openssl.cc.o): in function `trantor::utils::sha256(void const*, unsigned long)`:
openssl.cc:(.text+0x1c0): undefined reference to `EVP_MD_fetch`
/bin/ld: openssl.cc:(.text+0x22c): undefined reference to `EVP_MD_free`
/bin/ld: ../trantor/libtrantor.a(openssl.cc.o): in function `trantor::utils::sha3(void const*, unsigned long)`:
openssl.cc:(.text+0x284): undefined reference to `EVP_MD_fetch`
/bin/ld: openssl.cc:(.text+0x2f0): undefined reference to `EVP_MD_free`
/bin/ld: ../trantor/libtrantor.a(openssl.cc.o): in function `trantor::utils::blake2b(void const*, unsigned long)`:
openssl.cc:(.text+0x348): undefined reference to `EVP_MD_fetch`
/bin/ld: openssl.cc:(.text+0x3b4): undefined reference to `EVP_MD_free`
collect2: error: ld returned 1 exit status
make[2]: *** [examples/CMakeFiles/client.dir/build.make:105: examples/client] Error 1
make[1]: *** [CMakeFiles/Makefile2:293: examples/CMakeFiles/client.dir/all] Error 2

That error is because of the older OpenSSL version the system has, according to cmake output.

Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "1.1.1f")

So I installed the newest version (https://www.openssl.org/source/) locally ($HOME/.local) as well.

The OpenSSL installation was successful, but when I tried the drogon installation again, I got the same error at the make step, with the same error message. Even cmake produced the same output as above for the OpenSSL path and its version.

My question is, how do you make cmake look for stuff locally? Like other installation processes, such as ./configure, you can add CFLAGS="-I/usr/local/include" option. Is there a similar method for cmake?

英文:

I'm trying to install C++ web framework, drogon, which requires following steps to install.

cd $WORK_PATH
git clone https://github.com/drogonframework/drogon
cd drogon
git submodule update --init
mkdir build
cd build
cmake ..
make && sudo make install

To install locally, I added the following command option,
cmake --install-prefix=$HOME/local.

However, the make process ended up like this,

/bin/ld: ../trantor/libtrantor.a(OpenSSLProvider.cc.o): in function `OpenSSLProvider::processHandshake()':
OpenSSLProvider.cc:(.text._ZN15OpenSSLProvider16processHandshakeEv[_ZN15OpenSSLProvider16processHandshakeEv]+0x504): undefined reference to `SSL_get1_peer_certificate'
/bin/ld: ../trantor/libtrantor.a(openssl.cc.o): in function `trantor::utils::md5(void const*, unsigned long)':
openssl.cc:(.text+0x35): undefined reference to `EVP_MD_fetch'
/bin/ld: openssl.cc:(.text+0xa1): undefined reference to `EVP_MD_free'
/bin/ld: ../trantor/libtrantor.a(openssl.cc.o): in function `trantor::utils::sha1(void const*, unsigned long)':
openssl.cc:(.text+0xfc): undefined reference to `EVP_MD_fetch'
/bin/ld: openssl.cc:(.text+0x168): undefined reference to `EVP_MD_free'
/bin/ld: ../trantor/libtrantor.a(openssl.cc.o): in function `trantor::utils::sha256(void const*, unsigned long)':
openssl.cc:(.text+0x1c0): undefined reference to `EVP_MD_fetch'
/bin/ld: openssl.cc:(.text+0x22c): undefined reference to `EVP_MD_free'
/bin/ld: ../trantor/libtrantor.a(openssl.cc.o): in function `trantor::utils::sha3(void const*, unsigned long)':
openssl.cc:(.text+0x284): undefined reference to `EVP_MD_fetch'
/bin/ld: openssl.cc:(.text+0x2f0): undefined reference to `EVP_MD_free'
/bin/ld: ../trantor/libtrantor.a(openssl.cc.o): in function `trantor::utils::blake2b(void const*, unsigned long)':
openssl.cc:(.text+0x348): undefined reference to `EVP_MD_fetch'
/bin/ld: openssl.cc:(.text+0x3b4): undefined reference to `EVP_MD_free'
collect2: error: ld returned 1 exit status
make[2]: *** [examples/CMakeFiles/client.dir/build.make:105: examples/client] Error 1
make[1]: *** [CMakeFiles/Makefile2:293: examples/CMakeFiles/client.dir/all] Error 2

That error is because of the older OpenSSL version the system has, according to cmake output.

Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "1.1.1f")  

So I installed newest version (https://www.openssl.org/source/) local ($HOEM/.local) as well.

The OpenSSL installation was successful but when I tried the drogon installation again, I got bounced off at the same step make with same error.
Even cmake produced the same output as above for the OpenSSL path and its version.

My question is how do you make cmake look for stuff locally ?
Like other installation process like ./configure, you can add CFLAGS="-I/usr/local/include option.
Is there similar method to cmake ?

答案1

得分: 1

一般情况下,这取决于CMake项目搜索其依赖项的方式。如果项目使用find_package(<Package>),在许多情况下,您可以设置一个变量<Package>_ROOT,指向该包的安装前缀。对于OpenSSL,您需要使用OPENSSL_ROOT_DIR,如此文档所述此处

因此,您需要使用以下命令配置项目:

cmake -DOPENSSL_ROOT_DIR=${HOME}/.local ..

在删除构建目录之后。

英文:

In general it depends on how the CMake projects is searching for its dependencies. If the project uses find_package(<Package>), in many cases you can set a variable <Package>_ROOT to point to the installation prefix of the package. In the case of OpenSSL you'll need to use OPENSSL_ROOT_DIR as documented here.

So you need to configure the project with

cmake -DOPENSSL_ROOT_DIR=${HOME}/.local ..

after deleting the build directory.

huangapple
  • 本文由 发表于 2023年5月17日 09:27:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76268016.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定