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

Building packages using Autotools fails for macOS passing detected CMAKE_<LANG>_COMPILER #589

Closed
czoido opened this issue Nov 14, 2023 · 3 comments

Comments

@czoido
Copy link
Contributor

czoido commented Nov 14, 2023

Hi!

I am encountering an issue when trying to build libcurl, which uses Autotools, with cmake-conan on macOS. The problem appears to be related to the absolute paths detected for the C and C++ compilers. This can be replicated with a simple example, as shown here: https://github.com/czoido/cmake-conan-example

...
checking for path separator... :
checking for sed... /usr/bin/sed
checking for grep... /usr/bin/grep
checking that grep -E works... yes
checking for ar... /usr/bin/ar
checking for a BSD-compatible install... /usr/local/bin/ginstall -c
checking for gcc... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
checking whether the C compiler works... no
configure: error: in `/Users/carlosz/.conan2/p/b/libcue2d65d5f375a7/b/build-release':
configure: error: C compiler cannot create executables
See `config.log' for more details
...

When running this example on macOS, CMAKE_CXX_COMPILER is detected as /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++. This seems to cause the build process for libcurl with Autotools to fail. However, if I manually change the compilers to /usr/bin/g++ and /usr/bin/cc, the build completes without any issues.

@jcar87
Copy link
Contributor

jcar87 commented Nov 15, 2023

Interesting!
I'd have to have a look at that config.log, this should be easy to reproduce outside of cmake-conan either way.

My suspicion is that this executable alone: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ is not properly configured when invoked directly - only when invoked via xcrun does it work properly, presumaly something else gets set up along the way (I think the SDKROOT is what xcrun passes) (note that /usr/bin/g++, /usr/bin/clang/, /usr/bin/cc and similar are all run via xcrun).

CMake most likely derives the compiler flags required for it to work, and thus can bypass xcrun completely.

Will look into this !

@czoido
Copy link
Contributor Author

czoido commented Nov 16, 2023

Thanks a lot. I can copy the relevant part of the failing log:

configure:4917: checking whether the C compiler works
configure:4939: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc  -m64 -fPIC -O3  -DNDEBUG -I/Users/carlosz/.conan2/p/b/zlib18a00e431d771/p/include  -m64 -L/Users/carlosz/.conan2/p/b/zlib18a00e431d771/p/lib conftest.c  -lz >&5
ld: library 'System' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
configure:4943: $? = 1
configure:4983: result: no
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "curl"
| #define PACKAGE_TARNAME "curl"
| #define PACKAGE_VERSION "-"
| #define PACKAGE_STRING "curl -"
| #define PACKAGE_BUGREPORT "a suitable curl mailing list: https://curl.se/mail/"
| #define PACKAGE_URL ""
| /* end confdefs.h.  */
| 
| int main (void)
| {
| 
|  ;
|  return 0;
| }
configure:4988: error: in `/Users/carlosz/.conan2/p/b/libcu3262009bef6bc/b/build-release':
configure:4990: error: C compiler cannot create executables
See `config.log' for more details

Versus a succesfull log invoking gcc:

configure:4917: checking whether the C compiler works
configure:4939: gcc  -m64 -fPIC -O3  -DNDEBUG -I/Users/carlosz/.conan2/p/b/zlib18a00e431d771/p/include  -m64 -L/Users/carlosz/.conan2/p/b/zlib18a00e431d771/p/lib conftest.c  -lz >&5
configure:4943: $? = 0
configure:4993: result: yes

Yes, I think that's the cause of the problem, that the gcc shim invokes xcrun and thereby ensures a properly configured environment for the compiler and linker.

@jcar87
Copy link
Contributor

jcar87 commented Nov 17, 2023

Fixed in #592.

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

No branches or pull requests

2 participants