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 on OS X: LLVM, flags #105

Open
IngwiePhoenix opened this issue Feb 4, 2019 · 3 comments
Open

Building on OS X: LLVM, flags #105

IngwiePhoenix opened this issue Feb 4, 2019 · 3 comments

Comments

@IngwiePhoenix
Copy link

I wanted to try out c2 and went ahead and tried to build right away. Well, this is unfortunately what happened:

[email protected] ~/W/g/c/out $ cmake .. -G Ninja -DCMAKE_CXX_COMPILER="/usr/local/opt/llvm/bin/clang++" -DCMAKE_C_COMPILER=/usr/local/opt/llvm/bin/clang -DCMAKE_CXX_FLAGS="-I /usr/local/opt/llvm/include -std=c++11" -DCMAKE_EXE_LINKER_FLAGS="-L /usr/local/opt/llvm/lib"
-- The CXX compiler identification is Clang 7.0.1
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Ingwie/Work/git/c2compiler/out
[email protected] ~/W/g/c/out $ ninja
[98/98] Linking CXX executable c2c/c2c
FAILED: c2c/c2c 
: && clang++  -I /usr/local/opt/llvm/include -std=c++11 -O3 -DNDEBUG -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names -L /usr/local/opt/llvm/lib c2c/CMakeFiles/c2c.dir/main.cpp.o  -o c2c/c2c  c2c/libc2core.a -lncurses && :
Undefined symbols for architecture x86_64:
  "llvm::AllocaInst::setAlignment(unsigned int)", referenced from:

...big snip...

What I had to do beforehand was to install LLVM via Homebrew (brew install llvm). Now, what I am guessing is that there are a lot of flags missing, possibly due to llvm-config not being in my $PATH by default. I would suggest you to use the LLVM CMake files.

[email protected] ~/W/g/c/out $ tree /usr/local/opt/llvm/share/cmake/
/usr/local/opt/llvm/share/cmake/
└── [ 928]  modules
    ├── [ 61K]  AddLLVM.cmake
    ├── [ 585]  AddLLVMDefinitions.cmake
    ├── [7.6K]  AddOCaml.cmake
    ├── [3.4K]  AddSphinxTarget.cmake
    ├── [5.7K]  CMakeLists.txt
    ├── [3.4K]  CheckAtomic.cmake
    ├── [2.2K]  CheckCompilerVersion.cmake
    ├── [ 193]  CheckLinkerFlag.cmake
    ├── [3.8K]  ChooseMSVCCRT.cmake
    ├── [2.9K]  CrossCompile.cmake
    ├── [ 470]  DetermineGCCCompatible.cmake
    ├── [ 724]  FindLibpfm.cmake
    ├── [2.3K]  FindOCaml.cmake
    ├── [ 939]  FindSphinx.cmake
    ├── [1.2K]  GenerateVersionFromCVS.cmake
    ├── [ 857]  GetHostTriple.cmake
    ├── [4.8K]  GetSVN.cmake
    ├── [ 38K]  HandleLLVMOptions.cmake
    ├── [1.0K]  HandleLLVMStdlib.cmake
    ├── [ 12K]  LLVM-Config.cmake
    ├── [2.8K]  LLVMConfig.cmake.in
    ├── [ 533]  LLVMConfigVersion.cmake.in
    ├── [8.7K]  LLVMExternalProjectUtils.cmake
    ├── [ 564]  LLVMInstallSymlink.cmake
    ├── [3.5K]  LLVMProcessSources.cmake
    ├── [7.2K]  TableGen.cmake
    └── [3.3K]  VersionFromVCS.cmake

Could save you some troubble. :)

I'll try and see if I can find a workaround here. By looking at my CMake invocation above, you can already see a bit of that.

@IngwiePhoenix
Copy link
Author

Well, here we are.

My workaround was to utilize environment variables, since string-substitution in the fish shell is not that great. So here is a direct copy of what I did:

[email protected] ~/W/g/c/out $ set LLVM_LIBS (/usr/local/opt/llvm/bin/llvm-config --libs)
[email protected] ~/W/g/c/out $ set LLVM_CFLAGS (/usr/local/opt/llvm/bin/llvm-config --cflags)
[email protected] ~/W/g/c/out $ set LLVM_CXXFLAGS (/usr/local/opt/llvm/bin/llvm-config --cxxflags)
[email protected] ~/W/g/c/out $ set LLVM_LDFLAGS (/usr/local/opt/llvm/bin/llvm-config --ldflags)
[email protected] ~/W/g/c/out $ rm -rf *
[email protected] ~/W/g/c/out $ cmake .. -G Ninja -DCMAKE_CXX_COMPILER="/usr/local/opt/llvm/bin/clang++" -DCMAKE_C_COMPILER=/usr/local/opt/llvm/bin/clang -DCMAKE_CXX_FLAGS="-I /usr/local/opt/llvm/include -std=c++11 $LLVM_CXXFLAGS" -DCMAKE_EXE_LINKER_FLAGS="$LLVM_LDFLAGS $LLVM_LIBS"
-- The CXX compiler identification is Clang 7.0.1
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++
-- Check for working CXX compiler: /usr/local/opt/llvm/bin/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/Ingwie/Work/git/c2compiler/out
[email protected] ~/W/g/c/out $ ninja
[57/98] Building CXX object c2c/CMakeFiles/c2core.dir/Analyser/FunctionAnalyser.cpp.o
../c2c/Analyser/FunctionAnalyser.cpp:2178:21: warning: variable length arrays are a C99 feature [-Wvla-extension]
    char enumHandled[ETD->numConstants()];
                    ^
1 warning generated.
[67/98] Building CXX object c2c/CMakeFiles/c2core.dir/Algo/TagWriter.cpp.o
../c2c/Algo/TagWriter.cpp:197:18: warning: variable length arrays are a C99 feature [-Wvla-extension]
    char* offsets[files.size()];
                 ^
1 warning generated.
[92/98] Building CXX object tools/CMakeFiles/tester.dir/tester/main.cpp.o
../tools/tester/main.cpp:1183:29: warning: cast from 'const char *' to 'char *' drops const qualifier [-Wcast-qual]
        char* end = (char*) &target[strlen(target) -1];
                            ^
1 warning generated.
[98/98] Linking CXX executable c2c/c2c

Hope it helps!

@bvdberg
Copy link
Member

bvdberg commented Feb 4, 2019 via email

@IngwiePhoenix
Copy link
Author

If you need anything tested on a Mac, feel free to ask. :)

Also: Travis offers building on OS X as well. So technically, you can use that too.

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