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

cmake encounter error on mac #360

Closed
luckypoem opened this issue Jun 6, 2016 · 39 comments
Closed

cmake encounter error on mac #360

luckypoem opened this issue Jun 6, 2016 · 39 comments

Comments

@luckypoem
Copy link

hi.
git clone https://github.com/libevent/libevent
cd libevent
mkdir build
cd build
cmake ..

it exports:
...
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
system variable OPENSSL_ROOT_DIR (missing: OPENSSL_INCLUDE_DIR)
...

but actually previously i already installed openssl on mac successfully:
$ git clone https://github.com/openssl/openssl
$ cd openssl
yudeMacBook-Air:openssl brite$ export CPPFLAGS=-I/usr/local/cellar/openssl/include
yudeMacBook-Air:openssl brite$ export LDFLAGS=-L/usr/local/cellar/openssl/lib
yudeMacBook-Air:openssl brite$ ./config --prefix=/usr/local/cellar/openssl/
yudeMacBook-Air:openssl brite$ make
yudeMacBook-Air:openssl brite$ make install

so,how to fix the issue?

@azat
Copy link
Member

azat commented Jun 7, 2016

@luckypoem can you dump env before cmake .. ?

@errzey
Copy link
Contributor

errzey commented Jun 13, 2016

Try out

brew upgrade openssl
brew link --force openssl
pkg-config --modversion openssl

@errzey
Copy link
Contributor

errzey commented Jun 18, 2016

Tested on OSX+brew, after uninstalling and reinstalling OpenSSL I got the same type of error:

CMake Error at /usr/local/Cellar/cmake/3.5.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
  Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
  system variable OPENSSL_ROOT_DIR (missing: OPENSSL_INCLUDE_DIR)
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.5.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/Cellar/cmake/3.5.2/share/cmake/Modules/FindOpenSSL.cmake:370 (find_package_handle_standard_args)
  CMakeLists.txt:670 (find_package)

After the above commands:

-- Found OpenSSL: /usr/local/Cellar/openssl/1.0.2h_1/lib/libssl.dylib;/usr/local/Cellar/openssl/1.0.2h_1/lib/libcrypto.dylib (found version "1.0.2h")
-- OpenSSL include: /usr/local/Cellar/openssl/1.0.2h_1/include
-- OpenSSL lib: /usr/local/Cellar/openssl/1.0.2h_1/lib/libssl.dylib;/usr/local/Cellar/openssl/1.0.2h_1/lib/libcrypto.dylib
-- Looking for pthread.h
-- Looking for pthread.h - found

So that works. Mind if I close?

@luckypoem
Copy link
Author

what commands are your " the above commands"?

@errzey
Copy link
Contributor

errzey commented Jun 19, 2016

#360 (comment)

@lifejuggler
Copy link

there are no commands in the #360 ... only messages. what commands did you use to make it work?

@errzey
Copy link
Contributor

errzey commented Jun 21, 2016

OK, again:

brew upgrade openssl
brew link --force openssl
pkg-config --modversion openssl

@lifejuggler
Copy link

lifejuggler commented Jun 21, 2016

That command doesn't seem to work...

-> libevent-2.0.22-stable brew upgrade openssl
  Error: openssl 1.0.2h_1 already installed
-> libevent-2.0.22-stable pkg-config --modversion openssl
  1.0.2h
-> libevent-2.0.22-stable brew link --force openssl
  Warning: Already linked: /usr/local/Cellar/openssl/1.0.2h_1
  To relink: brew unlink openssl && brew link openssl 
-> libevent-2.0.22-stable ./configure && make
  ...
  bufferevent_openssl.c:60:10: fatal error: 'openssl/bio.h' file not found
  #include <openssl/bio.h>
         ^
  1 error generated.
  make[2]: *** [bufferevent_openssl.lo] Error 1
  make[1]: *** [all-recursive] Error 1
  make: *** [all] Error 2

@errzey
Copy link
Contributor

errzey commented Jun 21, 2016

Oh, 2.0. You can try out the OPENSSL_LIBADD env flag.

@azat
Copy link
Member

azat commented Oct 2, 2016

@luckypoem / @lifejuggler any progress?

@lifejuggler
Copy link

adding the flag worked for me. I dunno about luckypoem

@kerneljake
Copy link

The following worked for me with 2.0.21-stable on El Capitan 10.11.6 :
$ CPPFLAGS=-I/opt/local/include ./configure --prefix=/opt/local
$ make

@azat
Copy link
Member

azat commented Oct 18, 2016

Okay, I guess this can be closed.

@azat azat closed this as completed Oct 18, 2016
@nquoctuan
Copy link

Hi guys,

I am quite new to this lib, can you give me more detail how to fix it by adding flag?

thanks,
Jimmy.

@nquoctuan
Copy link

I did follow @kerneljake , but i got errors below:

/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-am
  CC       libevent_openssl_la-bufferevent_openssl.lo
bufferevent_openssl.c:66:10: fatal error: 'openssl/bio.h' file not found
#include <openssl/bio.h>
         ^
1 error generated.
make[1]: *** [libevent_openssl_la-bufferevent_openssl.lo] Error 1
make: *** [all] Error 2

@azat
Copy link
Member

azat commented Feb 13, 2017

@nquoctuan do you use brew?

AFAIR there are some changes with locations oh libs/headers (on 10.12 or so) so can you try something like this instead CPPFLAGS=-I/usr/local/opt/openssl

P.S. totally untested.

@nquoctuan
Copy link

Hi @azat ,

Yes, i try to build libevent for compiling thrift on macos.

Below is the result of brew info openssl

openssl: stable 1.0.2k (bottled) [keg-only]
SSL/TLS cryptography library
https://openssl.org/
/usr/local/Cellar/openssl/1.0.2k (1,696 files, 12M)
  Poured from bottle on 2017-02-13 at 17:42:51
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/openssl.rb
==> Dependencies
Build: makedepend ✘
==> Options
--universal
	Build a universal binary
--without-test
	Skip build-time tests (not recommended)
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include
For pkg-config to find this software you may need to set:
    PKG_CONFIG_PATH: /usr/local/opt/openssl/lib/pkgconfig

Any ideas?
Thanks

@azat
Copy link
Member

azat commented Feb 14, 2017

You can try next:

autotools

  • pass -I to the compiler
export CPPFLAGS=-I/usr/local/opt/openssl/include
export LDFLAGS=-L/usr/local/opt/openssl/lib
./configure
./make
  • let pkg-config take care
PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig ./configure && make

cmake

  • -DOPENSSL_ROOT=/usr/local/opt/openssl

And for now autotools is preferable build system.

@nquoctuan
Copy link

Thanks @azat , i will try it now.

@songhao8080
Copy link

@nquoctuan can you fix it

@Shunzi007
Copy link

Shunzi007 commented Feb 2, 2018

I find the above solutions don't work for macos 10.13.3 now!
Could I add something in the CMakeList.txt or the build.sh

cmake -DCMAKE_TOOLCHAIN_FILE=./ios.cmake -DIOS_PLATFORM=OS -H. -BXcode -GXcode

@azat
Copy link
Member

azat commented Feb 3, 2018

@Shunzi007 are you sure that openssl installed at /usr/local/opt/openssl (i.e. it contains lib/include and others) ?

@Shunzi007
Copy link

@azat Yes, I am sure. if I run
cmake -H. -BXcode -GXcode -DOPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.2n -DOPENSSL_LIBRARIES=/usr/local/Cellar/openssl/1.0.2n/lib ..
it goes well in this repository.

However, in my project, in which libevent is a subdirectory, I run cmake command
cmake -DCMAKE_TOOLCHAIN_FILE=./ios.cmake -DIOS_PLATFORM=OS -H. -BXcode -GXcode -DOPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.2n -DOPENSSL_LIBRARIES=/usr/local/Cellar/openssl/1.0.2n/lib
will show the error

CMake Error at /usr/local/Cellar/cmake/3.10.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:137 (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):
/usr/local/Cellar/cmake/3.10.2/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
/usr/local/Cellar/cmake/3.10.2/share/cmake/Modules/FindOpenSSL.cmake:390 (find_package_handle_standard_args)
libevent/CMakeLists.txt:695 (find_package)

so I wonder whether could I add some line into the CMakeList.txt.
Thank you.

@azat
Copy link
Member

azat commented Feb 4, 2018

@Shunzi007 I don't think that the problem is in libevent's cmake rules, could you post output of cmake --trace .... ?

(upd: better upload it to some pastebin and post the link here)

@Shunzi007
Copy link

Shunzi007 commented Feb 4, 2018

do cmake -DOPENSSL_ROOT=/usr/local/opt/openssl .. in libenvent/build could get(https://gist.github.com/Shunzi007/7a45b4d848317eedd1e5b252aced43c8)
so your reply on 14 Feb 2017

You can try next:

autotools
pass -I to the compiler
export CPPFLAGS=-I/usr/local/opt/openssl/include
export LDFLAGS=-L/usr/local/opt/openssl/lib
./configure
./make
let pkg-config take care
PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig ./configure && make
cmake
-DOPENSSL_ROOT=/usr/local/opt/openssl
And for now autotools is preferable build system.

the last suggestion goes wrong now?

cmake -DOPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.2n -DOPENSSL_LIBRARIES=/usr/local/Cellar/openssl/1.0.2n/lib .. goes well.

@azat
Copy link
Member

azat commented Feb 4, 2018

I'm not sure that I understand you @Shunzi007
If I understand you correctly then cmake from the root directory of the libevent works, but not from subdirectory.

Could you post the full (by full I mean run of cmake without any cache, i.e. from the clean/new build directory) output of (with --trace):

  • cmake -DCMAKE_TOOLCHAIN_FILE=./ios.cmake -DIOS_PLATFORM=OS -H. -BXcode -GXcode -DOPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.2n -DOPENSSL_LIBRARIES=/usr/local/Cellar/openssl/1.0.2n/lib --trace # from subdir
  • cmake -H. -BXcode -GXcode -DOPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.2n -DOPENSSL_LIBRARIES=/usr/local/Cellar/openssl/1.0.2n/lib .. --trace # from the root dir of libevent

Without this I cannot help you, since I don't know any details.

@Shunzi007
Copy link

@azat cmake -DCMAKE_TOOLCHAIN_FILE=./ios.cmake -DIOS_PLATFORM=OS -H. -BXcode -GXcode -DOPENSSL_ROOT_DIR=/usr/local/Cellar/openssl/1.0.2n -DOPENSSL_LIBRARIES=/usr/local/Cellar/openssl/1.0.2n/lib --trace
from subdir
(https://gist.github.com/Shunzi007/056690f845718b92e332b993d2d06054)
Thank you very much.

@azat
Copy link
Member

azat commented Feb 4, 2018

Just like I though, looks like OPENSSL_INCLUDE_DIR=/usr/local/Cellar/openssl/1.0.2n/include and it does not contains openssl/ssl.h and/or openssl/opensslv.h

Post the output of find /usr/local/Cellar/openssl/1.0.2n/ into gist please.

BTW if you installed openssl correctly then you don't have to set OPENSSL_LIBRARIES (it will be installed by find_package(OpenSSL))

@Shunzi007
Copy link

find /usr/local/Cellar/openssl/1.0.2n/
(https://gist.github.com/Shunzi007/12d4600c8d5b59fb7f1057d2f896136c)

@ploxiln
Copy link
Contributor

ploxiln commented Feb 5, 2018

I see references to "ios", is this for iPhone / iPad? Which are ARMv8 architecture? The x86_64 openssl built by homebrew won't work for that.

@ploxiln
Copy link
Contributor

ploxiln commented Feb 5, 2018

/Users/wangshun/Code/ios-cmake/ios.cmake(75):  set(IOS_PLATFORM_LOCATION iPhoneOS.platform )
/Users/wangshun/Code/ios-cmake/ios.cmake(78):  set(CMAKE_XCODE_EFFECTIVE_PLATFORMS -iphoneos )
...
/Users/wangshun/Code/ios-cmake/ios.cmake(127): set(IOS_ARCH armv7 armv7s arm64 )

Looks like.

@Shunzi007
Copy link

@ploxiln Yes, it is an iOS app. I want to start a server in it. so I need to build a arm64 openssl for it? I will have a try.

@azat
Copy link
Member

azat commented Feb 5, 2018

Yeah, but this will explains why it will not link with them, but not the fact that it cannot find it, it cannot detect even the version from the header, even though it exists.

Obviously, I'm missing something here..

@azat
Copy link
Member

azat commented Feb 5, 2018

And the reason this is CMAKE_FIND_ROOT_PATH

/Users/wangshun/Code/ios-cmake/ios.cmake(137):  set(CMAKE_FIND_ROOT_PATH ${CMAKE_IOS_DEVELOPER_ROOT} ${CMAKE_IOS_SDK_ROOT} ${CMAKE_PREFIX_PATH} CACHE string iOS find search path root )

Since CMAKE_FIND_ROOT_PATH will be prepended for every find_*() according to cross compiling doc

@Shunzi007
Copy link

@azat Yes, I think the main problem is cmake can not find openssl. I have tried with (https://github.com/x2on/OpenSSL-for-iPhone) to get openssl for iOS, and then use cmake -H. -BXcode -GXcode -DOPENSSL_ROOT_DIR=/Users/h172462/Code/OpenSSL-for-iPhone/bin/iPhoneOS11.2-arm64.sdk -DOPENSSL_LIBRARIES=/Users/h172462/Code/OpenSSL-for-iPhone/bin/iPhoneOS11.2-arm64.sdk/lib, but it still tells the error.
As I am a new hand of cmake, could you give me some suggestion ?
Or I wonder if could I disable openssl to just pass build?

@Shunzi007
Copy link

Hi guys, I have found a way to fix the cmake issue, I just add library and include path and the command now is
cmake -DCMAKE_TOOLCHAIN_FILE=./ios.cmake -DIOS_PLATFORM=OS -H. -BXcode -GXcode -DOPENSSL_SSL_LIBRARY=/Users/h172462/Code/OpenSSL-for-iPhone/lib/libssl.a -DOPENSSL_CRYPTO_LIBRARY=/Users/h172462/Code/OpenSSL-for-iPhone/lib/libcrypto.a -DOPENSSL_INCLUDE_DIR=/Users/h172462/Code/OpenSSL-for-iPhone/include
openssl is working now.

@azat
Copy link
Member

azat commented Feb 6, 2018

This is an option, but not a good thing to do, you should base your openssl location against your CMAKE_FIND_ROOT_PATH and pass only OPENSSL_ROOT_DIR (that should be in inside your CMAKE_FIND_ROOT_PATH).

Please read the cross compiling doc from #360 (comment)

And to turn off openssl you could add -DEVENT__DISABLE_OPENSSL=ON

@Shunzi007
Copy link

Shunzi007 commented Feb 7, 2018

@azat Hi, the project still has build errors, I need your help.
use cmake 3.10.2 macOS 10.13 and Xcode 9.2
the step is

  1. git clone https://github.com/libevent/libevent.git

  2. cd libevent

  3. curl https://gist.githubusercontent.com/Shunzi007/6fb7fb8f779fc6034e3196d74b22df01/raw/280f7ca20204c8c1d9013ac47da91fae5183e3b2/ios.cmake > ios.cmake

  4. git clone https://github.com/x2on/OpenSSL-for-iPhone

  5. cd OpenSSL-for-iPhone && ./build-libssl.sh --version=1.0.2n

  6. cd ..

  7. cmake -DCMAKE_TOOLCHAIN_FILE=./ios.cmake -DIOS_PLATFORM=OS -H. -BXcode -GXcode -DOPENSSL_SSL_LIBRARY=./OpenSSL-for-iPhone/lib/libssl.a -DOPENSSL_CRYPTO_LIBRARY=./OpenSSL-for-iPhone/lib/libcrypto.a -DOPENSSL_INCLUDE_DIR=./OpenSSL-for-iPhone/include -DEVENT__DISABLE_THREAD_SUPPORT=ON -DIOS_TARGET:STRING=8.0 -DCMAKE_BUILD_TYPE=Debug

Here is the result (https://gist.github.com/Shunzi007/423ec8d0604cb35f1d0263613e20fca6)
It builds succeed, but tells errors when opened by Xcode.
wx20180207-163819 2x

Could you have a try and help me fix these?

@azat
Copy link
Member

azat commented Feb 7, 2018

I guess it just cannot find path to headers, that created by cmake, particularly:

include/evconfig-private.h
include/event2/event-config.h

And I don't know how xcode doing this, so you have to figure this out by yourself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

9 participants