alliedmodders / sourcemod

SourceMod - Source Engine Scripting and Administration
http://www.sourcemod.net/
985 stars 423 forks source link

OSX: No suitable C/C++ compiler was found. #1675

Closed Lidbetter closed 2 years ago

Lidbetter commented 2 years ago

Help us help you

Environment

Description

Following the instructions here: https://wiki.alliedmods.net/Building_SourceMod#Mac_OS_X

I get to:

$ python ../configure.py
Checking CC compiler (vendor test gcc)... ['clang', '-m32', '-arch', 'i386', 'test.c', '-o', 'test-c']
Compiler clang for CC failed: Compiler failed with return code 1
Checking CC compiler (vendor test gcc)... ['gcc', '-m32', '-arch', 'i386', '-arch', 'i386', 'test.c', '-o', 'test-c']
Compiler gcc for CC failed: Compiler failed with return code 1
Checking CC compiler (vendor test gcc)... ['icc', '-m32', '-arch', 'i386', '-arch', 'i386', '-arch', 'i386', 'test.c', '-o', 'test-c']
Compiler icc for CC failed: [Errno 2] No such file or directory: 'icc'
Skipping target x86: Unable to find a suitable C/C++ compiler
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/ambuild2/frontend/v2_2/prep.py", line 137, in Configure
    if not cm.generate(options.generator):
  File "/usr/local/lib/python3.9/site-packages/ambuild2/frontend/context_manager.py", line 93, in generate
    self.parseBuildScripts()
  File "/usr/local/lib/python3.9/site-packages/ambuild2/frontend/v2_2/context_manager.py", line 50, in parseBuildScripts
    self.execContext(cx)
  File "/usr/local/lib/python3.9/site-packages/ambuild2/frontend/v2_2/context_manager.py", line 148, in execContext
    exec(code, scriptGlobals)
  File "/Users/robinlidbetter/code/alliedmodders/sourcemod/AMBuildScript", line 732, in <module>
    SM = SMConfig()
  File "/Users/robinlidbetter/code/alliedmodders/sourcemod/AMBuildScript", line 148, in __init__
    raise Exception('No suitable C/C++ compiler was found.')
Exception: No suitable C/C++ compiler was found.
Configure failed: No suitable C/C++ compiler was found.

clang/gcc info:

$ xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates

$ which clang
/usr/bin/clang

$ clang -v
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: x86_64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

$ which gcc
/usr/bin/gcc

$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: x86_64-apple-darwin21.2.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
peace-maker commented 2 years ago

I don't think you can compile for 32 bit binaries in general on macOS anymore. It's 64bit only since a few versions. You need an older macos or xcode version, but I don't use macs, so can't tell you the details.

Wend4r commented 2 years ago

I also want to be able to build SourceMod on WSL1 that supports executing binaries in x86_64 mode, which leads to the same problem

wend4r@Wend4rPC:/mnt/d/C++/alliedmodders/sourcemod/build/linux_all$ ./initialize_release.sh
Checking CC compiler (vendor test gcc)... ['clang', '-m32', 'test.c', '-o', 'test-c']
Compiler clang for CC failed: failed to create executable with clang
Checking CC compiler (vendor test gcc)... ['gcc', '-m32', 'test.c', '-o', 'test-c']
Compiler gcc for CC failed: failed to create executable with gcc
Checking CC compiler (vendor test gcc)... ['icc', '-m32', 'test.c', '-o', 'test-c']
Compiler icc for CC failed: [Errno 2] No such file or directory: 'icc'
Skipping target x86: Unable to find a suitable C/C++ compiler
Traceback (most recent call last):
  File "/home/wend4r/.local/lib/python3.9/site-packages/ambuild2/frontend/v2_2/prep.py", line 137, in Configure
    if not cm.generate(options.generator):
  File "/home/wend4r/.local/lib/python3.9/site-packages/ambuild2/frontend/context_manager.py", line 93, in generate
    self.parseBuildScripts()
  File "/home/wend4r/.local/lib/python3.9/site-packages/ambuild2/frontend/v2_2/context_manager.py", line 50, in parseBuildScripts
    self.execContext(cx)
  File "/home/wend4r/.local/lib/python3.9/site-packages/ambuild2/frontend/v2_2/context_manager.py", line 148, in execContext
    exec(code, scriptGlobals)
  File "/mnt/d/C++/alliedmodders/sourcemod/AMBuildScript", line 738, in <module>
    SM = SMConfig()
  File "/mnt/d/C++/alliedmodders/sourcemod/AMBuildScript", line 148, in __init__
    raise Exception('No suitable C/C++ compiler was found.')
Exception: No suitable C/C++ compiler was found.
Configure failed: No suitable C/C++ compiler was found.
wend4r@Wend4rPC:/mnt/d/C++/alliedmodders/sourcemod/build/linux_all$ cd .ambuild2
wend4r@Wend4rPC:/mnt/d/C++/alliedmodders/sourcemod/build/linux_all/.ambuild2$ ls
graph  test.c  test.cpp  test-cxx  vars
wend4r@Wend4rPC:/mnt/d/C++/alliedmodders/sourcemod/build/linux_all/.ambuild2$ clang -m32 test.c -o test-c
wend4r@Wend4rPC:/mnt/d/C++/alliedmodders/sourcemod/build/linux_all/.ambuild2$ ./test-c
-bash: ./test-c: cannot execute binary file: Exec format error
Lidbetter commented 2 years ago

I have done some more digging. By installing xcode 9.4.1 (https://developer.apple.com/download/all/?q=Xcode%209.4.1) and running this to fixup things to make it work on Monterey: https://github.com/mrpippy/XcodeNueve

This succeeds: DEVELOPER_DIR=/Applications/Xcode9.app SDKROOT=/Applications/Xcode9.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk clang -m32 .ambuild2/test.c -o test-c

I'm having trouble figuring out how to modify ambuild to setup env in the context of clang / gcc execution

dvander commented 2 years ago

We only support macOS <= 10.14. It is still possible to build on newer versions, but it's most likely a lot of work. If you can get it to work on later versions, that's great, and feel free to update the wiki with instructions.

The problem with WSL1 (and assumedly macOS 10.15+) is that they don't support executing 32-bit code. AMBuild currently expects that an x86_64 OS can execute x86 code. But, we can build exceptions for this for WSL1 and macOS if you'd like. Please file an AMBuild bug and I'll fix it in the next few weeks.

Note, if you weren't aware, WSL2 is a true VM whereas WSL1 is emulated. I'd recommend using WSL2.

Lidbetter commented 2 years ago

It would be nice to get things working on newer osx versions, but I think given the hoops I had to jump through already + modifications needed to the build process, it's probably not worth it.

Compiling on linux in a vm or docker would probably be a better time investment.

Thanks for feedback regarding macos - I have updated the wiki to include info about 10.14 being a maximum supported version