yrnkrn / zapcc

zapcc is a caching C++ compiler based on clang, designed to perform faster compilations
Other
1.25k stars 60 forks source link

Cannot find stdlib headers on macOS #7

Closed emlai closed 6 years ago

emlai commented 6 years ago

Trying to compile a simple hello world:

#include <iostream>

int main() {
  std::cout << "Hello world!" << std::endl;
}

using the command zapcc main.cpp results in:

main.cpp:1:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
1 error generated.

Tried to include C stdlib headers too, same error.

Compiling the same file with the system clang works fine.

Built on macOS 10.13.5 with Xcode 9.4.1.

yrnkrn commented 6 years ago

When you build zapcc, you get clang as well. Does this newly builded clang (not the system one) find system includes correctly?

emlai commented 6 years ago

No it does not. Also tried clang++.

yrnkrn commented 6 years ago

clang on MacOS is somewhat different than the public trunk and maybe built with different options. If you can make build clang to find the includes, zapcc will behave the same, this code is identical between cland & zapcc. Do these settings (from https://embeddedartistry.com/blog/2017/2/20/installing-clangllvm-on-osx) help?

LDFLAGS += -L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib
CPPFLAGS += -I/usr/local/opt/llvm/include -I/usr/local/opt/llvm/include/c++/v1/
yrnkrn commented 6 years ago

Closing for now

nithishc829 commented 6 years ago

Okay Having the same issue in Windows. What include and header paths to provide if we are on windows ?

yrnkrn commented 6 years ago

On windows I target i686-pc-windows-gnu when building

cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_WARNINGS=OFF -DLLVM_DEFAULT_TARGET_TRIPLE=i686-pc-windows-gnu ../llvm

with mingw-w64 already available on the PATH. Then everything works without need to provide include or library paths. zapcc does not support targetting the Visual C++ headers/libs.

nithishc829 commented 6 years ago

I tried your command created another build directory and ran your command. Still it is giving error saying: C:\Users\nithish\Desktop\ZAPCC\zapcc-master\build>ninja [3213/3263] cmd.exe /C "cd /D C:\Users\nithish\Desktop\ZAPCC\zapcc-master\build...ls/zapccs/zapccs.config C:/Users/nithish/Desktop/ZAPCC/zapcc-master/build/./bin" FAILED: tools/zapccs/CMakeFiles/copy_config cmd.exe /C "cd /D C:\Users\nithish\Desktop\ZAPCC\zapcc-master\build\tools\zapccs && cp C:/Users/nithish/Desktop/ZAPCC/zapcc-master/tools/zapccs/zapccs.config C:/Use rs/nithish/Desktop/ZAPCC/zapcc-master/build/./bin" 'cp' is not recognized as an internal or external command, operable program or batch file. [3222/3263] Linking CXX executable bin\opt.exe ninja: build stopped: subcommand failed.

So I opened the msys2 and ran the same command again it finished with" ... [38/42] Building CXX object tools/zapccs/CMakeFiles/zapccs.dir/UnloaderDI.cpp.ob j [39/42] Building CXX object tools/zapccs/CMakeFiles/zapccs.dir/Unloader.cpp.obj [40/42] Linking CXX executable bin\zapcc.exe [41/42] Building CXX object tools/zapccs/CMakeFiles/zapccs.dir/UnloaderIR.cpp.ob j [42/42] Linking CXX executable bin\zapccs.exe " still I ended up getting$ ./zapcc++.exe temp.cpp C:\Users\nithish\Desktop\ZAPCC\zapcc-master\build\bin\temp.cpp:1:10: fatal error : 'iostream' file not found

include

     ^~~~~~~~~~

1 error generated.

I thought lets just compile the code and remove the print statements just to see if it builds an exe. now I am getting linker error like this Nithish@NITHISH MINGW64 /c/Users/nithish/Desktop/ZAPCC/zapcc-master/build/bin $ ./zapcc++.exe temp.cpp C:\msys64\mingw64\bin\ld.exe: cannot find crt2.o: No such file or directory C:\msys64\mingw64\bin\ld.exe: cannot find crtbegin.o: No such file or directory C:\msys64\mingw64\bin\ld.exe: cannot find -lstdc++ C:\msys64\mingw64\bin\ld.exe: cannot find -lmingw32 C:\msys64\mingw64\bin\ld.exe: cannot find -lgcc_s C:\msys64\mingw64\bin\ld.exe: cannot find -lgcc C:\msys64\mingw64\bin\ld.exe: cannot find -lmoldname C:\msys64\mingw64\bin\ld.exe: cannot find -lmingwex C:\msys64\mingw64\bin\ld.exe: cannot find -lmsvcrt C:\msys64\mingw64\bin\ld.exe: cannot find -ladvapi32 C:\msys64\mingw64\bin\ld.exe: cannot find -lshell32 C:\msys64\mingw64\bin\ld.exe: cannot find -luser32 C:\msys64\mingw64\bin\ld.exe: cannot find -lkernel32 C:\msys64\mingw64\bin\ld.exe: cannot find -lmingw32 C:\msys64\mingw64\bin\ld.exe: cannot find -lgcc_s C:\msys64\mingw64\bin\ld.exe: cannot find -lgcc C:\msys64\mingw64\bin\ld.exe: cannot find -lmoldname C:\msys64\mingw64\bin\ld.exe: cannot find -lmingwex C:\msys64\mingw64\bin\ld.exe: cannot find -lmsvcrt C:\msys64\mingw64\bin\ld.exe: cannot find crtend.o: No such file or directory zapcc++.exe: error: linker command failed with exit code 1 (use -v to see invoca tion)

Please if you could share some insights how to build and link zapcc in windows a step by step procedure that worked for you will be of lot of help.

yrnkrn commented 6 years ago

Added mingw-builds instructions in 069a2ce8d4f070b57e6486c58935d3b0a64a5b06.

nithishc829 commented 6 years ago

Thank you I will try it.

nithishc829 commented 6 years ago

Hi Sir Thank your inputs on "mingw-builds instructions in 069a2ce."

Attempt 1: I started fresh in command line and followed your instructions . It started to build however I got error at some 98% build is over " C:\Users\nithish\Desktop\ZAPCC\zapcc-master\build2>ninja [3210/3263] cmd.exe /C "cd /D C:\Users\nithish\Desktop\ZAPCC\zapcc-master\build2...s/zapccs/zapccs.config C:/Users/nithish/Desktop/ZAPCC/zapcc-master/build2/./bin" FAILED: tools/zapccs/CMakeFiles/copy_config cmd.exe /C "cd /D C:\Users\nithish\Desktop\ZAPCC\zapcc-master\build2\tools\zapccs && cp C:/Users/nithish/Desktop/ZAPCC/zapcc-master/tools/zapccs/zapccs.config C:/Us ers/nithish/Desktop/ZAPCC/zapcc-master/build2/./bin" 'cp' is not recognized as an internal or external command, operable program or batch file. [3219/3263] Building CXX object tools/zapcc/CMakeFiles/zapcc.dir/__/clang/tools/driver/cc1_main.cpp.obj ninja: build stopped: subcommand failed. " Attempt 1: Ended with error .... So I thought cp is linux command so it needs some linux bash kind of thing.

Attempt 2: I started fresh again in msys2 bash. I followed the steps you suggested yesterday - > "mingw-builds instructions in 069a2ce." I was able to build zapcc on my pc. I tried a simple C++ code and it compiles that's cool. But when I move out of msys2 bash I am getting error when I ran the same command to compile the simple C++ code. I get this error Zapcc++.exe -Entry Point Not Found. The procedure entry point __divmoddi4 could not be located in the dynamic link library libgcc_s_dw2-1.dll.

Attempt2 is working fine but I have dependency of msys2 bash I always need to use msys2 bash ? Can I not do the same in command line ? Any path I need to update in my env variable ? Could help me with this.?

yrnkrn commented 6 years ago

Maybe more than one gcc version is installed and the PATH is different outside bash so the other gcc is found.

nithishc829 commented 6 years ago

you were right I had multiple mingw installed in C folder. I removed all the extra copies of mingw Do I have to rebuild the zapccs again ? or just restart is enough?

nithishc829 commented 6 years ago

I rebuilt the zapcc again after I removed all duplicate copies mingw and even passed the compiler path in cmake -D option. Still i am facing same issue ... anything else that I need to try ?

yrnkrn commented 6 years ago

Please try starting starting from a new build with only the recommended mingw-builds gcc distribution installed.

nithishc829 commented 6 years ago

Sir I found the solution. Actually build was correct. For some reason the zapcc++.exe application from command line was not picking up the dlls present in "C:\mingw-w64\mingw32\bin" even after placing the dlls in the environment variable. So I copied all the dlls from "C:\mingw-w64\mingw32\bin" to the zapcc++.exe folder and it is working fine. Thanks for the help. Awesome work on zapcc to reduce the compilation time. I really liked it. Thanks again.