c2lang / c2compiler

the c2 programming language
c2lang.org
Apache License 2.0
704 stars 49 forks source link

Building on OS X: LLVM, flags #105

Open IngwiePhoenix opened 5 years ago

IngwiePhoenix commented 5 years ago

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

Ingwie@Ingwies-Macbook-Pro.local ~/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
Ingwie@Ingwies-Macbook-Pro.local ~/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.

Ingwie@Ingwies-Macbook-Pro.local ~/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 commented 5 years ago

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:

Ingwie@Ingwies-Macbook-Pro.local ~/W/g/c/out $ set LLVM_LIBS (/usr/local/opt/llvm/bin/llvm-config --libs)
Ingwie@Ingwies-Macbook-Pro.local ~/W/g/c/out $ set LLVM_CFLAGS (/usr/local/opt/llvm/bin/llvm-config --cflags)
Ingwie@Ingwies-Macbook-Pro.local ~/W/g/c/out $ set LLVM_CXXFLAGS (/usr/local/opt/llvm/bin/llvm-config --cxxflags)
Ingwie@Ingwies-Macbook-Pro.local ~/W/g/c/out $ set LLVM_LDFLAGS (/usr/local/opt/llvm/bin/llvm-config --ldflags)
Ingwie@Ingwies-Macbook-Pro.local ~/W/g/c/out $ rm -rf *
Ingwie@Ingwies-Macbook-Pro.local ~/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
Ingwie@Ingwies-Macbook-Pro.local ~/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 commented 5 years ago

Hi ,

I'll look into it. I dont have my Macbook with me now, but this afternoon I should have some time for it..

On Mon, Feb 4, 2019 at 2:52 AM Ingwie Phoenix notifications@github.com wrote:

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:

Ingwie@Ingwies-Macbook-Pro.local ~/W/g/c/out $ set LLVM_LIBS (/usr/local/opt/llvm/bin/llvm-config --libs) Ingwie@Ingwies-Macbook-Pro.local ~/W/g/c/out $ set LLVM_CFLAGS (/usr/local/opt/llvm/bin/llvm-config --cflags) Ingwie@Ingwies-Macbook-Pro.local ~/W/g/c/out $ set LLVM_CXXFLAGS (/usr/local/opt/llvm/bin/llvm-config --cxxflags) Ingwie@Ingwies-Macbook-Pro.local ~/W/g/c/out $ set LLVM_LDFLAGS (/usr/local/opt/llvm/bin/llvm-config --ldflags) Ingwie@Ingwies-Macbook-Pro.local ~/W/g/c/out $ rm -rf Ingwie@Ingwies-Macbook-Pro.local ~/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 Ingwie@Ingwies-Macbook-Pro.local ~/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!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/c2lang/c2compiler/issues/105#issuecomment-460110620, or mute the thread https://github.com/notifications/unsubscribe-auth/AAC1mrxUvIDIvdK8auCOXWVOJzq_bXUpks5vJ5JbgaJpZM4agcKS .

IngwiePhoenix commented 5 years ago

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.