I recently installed LLVM and Clang on my machine running windows 7. It also has cygwin installed. I went to the this URL and followed the instructions in Part 1 and Part 2. I installed MinGW for both 32 bits and 64 bits. However, I do not have the directory C:\mingw64 and I do not have the directory C:\mingw32. I do have a directory called C:\mingw and off of that I do have a directory mingw32.
I saved the two .bat files setgcc32 and setgcc64 on the page and ran them. When I try the following command line in 32 bit mode:
clang++ main.cpp -o main.exe -std=c++14
I get:
c:\Rtools\gcc-4.6.3\bin\ld.exe: cannot find -lgcc_s
c:\Rtools\gcc-4.6.3\bin\ld.exe: cannot find -lgcc_s
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
When I try it in 64 bit mode, I get:
main.cpp:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^
1 error generated.
What am I doing wrong?
When I run this command:
clang++ -v main.cpp -o main.exe -std=c++14
in 32 bit mode, I get:
clang version 3.7.0 (tags/RELEASE_370/rc3)
Target: i686-pc-windows-gnu
Thread model: posix
"C:\\Program Files (x86)\\LLVM\\bin\\clang++.exe" -cc1 -triple i686-pc-windows-
gnu -emit-obj -mrelax-all -disable-free -main-file-name main.cpp -mrelocation-mo
del static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mc
onstructor-aliases -target-cpu pentium4 -v -dwarf-column-info -resource-dir "C:\
\Program Files (x86)\\LLVM\\bin\\..\\lib\\clang\\3.7.0" -internal-isystem "c:\\R
tools\\gcc-4.6.3\\i686-w64-mingw32\\include\\c++" -internal-isystem "c:\\Rtools\
\gcc-4.6.3\\i686-w64-mingw32\\include\\c++\\i686-w64-mingw32" -internal-isystem
"c:\\Rtools\\gcc-4.6.3\\i686-w64-mingw32\\include\\c++\\backward" -internal-isys
tem "c:\\Rtools\\gcc-4.6.3\\i686-w64-mingw32\\include\\c++\\4.6.3" -internal-isy
stem "c:\\Rtools\\gcc-4.6.3\\i686-w64-mingw32\\include\\c++\\4.6.3\\i686-w64-min
gw32" -internal-isystem "c:\\Rtools\\gcc-4.6.3\\i686-w64-mingw32\\include\\c++\\
4.6.3\\backward" -internal-isystem "c:\\Rtools\\gcc-4.6.3\\include\\c++\\4.6.3"
-internal-isystem "c:\\Rtools\\gcc-4.6.3\\include\\c++\\4.6.3\\i686-w64-mingw32"
-internal-isystem "c:\\Rtools\\gcc-4.6.3\\include\\c++\\4.6.3\\backward" -inter
nal-isystem "c:\\Rtools\\gcc-4.6.3\\lib\\gcc\\i686-w64-mingw32\\4.6.3\\include\\
c++" -internal-isystem "c:\\Rtools\\gcc-4.6.3\\lib\\gcc\\i686-w64-mingw32\\4.6.3
\\include\\c++\\i686-w64-mingw32" -internal-isystem "c:\\Rtools\\gcc-4.6.3\\lib\
\gcc\\i686-w64-mingw32\\4.6.3\\include\\c++\\backward" -internal-isystem "C:\\Pr
ogram Files (x86)\\LLVM\\bin\\..\\lib\\clang\\3.7.0\\include" -internal-isystem
"c:\\Rtools\\gcc-4.6.3\\lib\\gcc\\i686-w64-mingw32\\4.6.3\\include" -internal-is
ystem "c:\\Rtools\\gcc-4.6.3\\i686-w64-mingw32/sys-root/mingw/include" -internal
-isystem "c:\\Rtools\\gcc-4.6.3\\lib\\gcc\\i686-w64-mingw32\\4.6.3\\include-fixe
d" -internal-isystem "c:\\Rtools\\gcc-4.6.3\\i686-w64-mingw32\\include" -interna
l-isystem "c:\\Rtools\\gcc-4.6.3\\include" -std=c++14 -fdeprecated-macro -fdebug
-compilation-dir "C:\\tmp6" -ferror-limit 19 -fmessage-length 80 -mstackrealign
-fno-use-cxa-atexit -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnosti
cs-show-option -fcolor-diagnostics -o "C:\\Users\\Bob\\AppData\\Local\\Temp\\mai
n-fdf675.o" -x c++ main.cpp
clang -cc1 version 3.7.0 based upon LLVM 3.7.0-rc3 default target i686-pc-window
s-gnu
ignoring nonexistent directory "c:\Rtools\gcc-4.6.3\i686-w64-mingw32\include\c++
"
ignoring nonexistent directory "c:\Rtools\gcc-4.6.3\i686-w64-mingw32\include\c++
\i686-w64-mingw32"
ignoring nonexistent directory "c:\Rtools\gcc-4.6.3\i686-w64-mingw32\include\c++
\backward"
ignoring nonexistent directory "c:\Rtools\gcc-4.6.3\i686-w64-mingw32\include\c++
\4.6.3"
ignoring nonexistent directory "c:\Rtools\gcc-4.6.3\i686-w64-mingw32\include\c++
\4.6.3\i686-w64-mingw32"
ignoring nonexistent directory "c:\Rtools\gcc-4.6.3\i686-w64-mingw32\include\c++
\4.6.3\backward"
ignoring nonexistent directory "c:\Rtools\gcc-4.6.3\lib\gcc\i686-w64-mingw32\4.6
.3\include\c++"
ignoring nonexistent directory "c:\Rtools\gcc-4.6.3\lib\gcc\i686-w64-mingw32\4.6
.3\include\c++\i686-w64-mingw32"
ignoring nonexistent directory "c:\Rtools\gcc-4.6.3\lib\gcc\i686-w64-mingw32\4.6
.3\include\c++\backward"
ignoring nonexistent directory "c:\Rtools\gcc-4.6.3\i686-w64-mingw32/sys-root/mi
ngw/include"
#include "..." search starts here:
#include <...> search starts here:
c:\Rtools\gcc-4.6.3\include\c++\4.6.3
c:\Rtools\gcc-4.6.3\include\c++\4.6.3\i686-w64-mingw32
c:\Rtools\gcc-4.6.3\include\c++\4.6.3\backward
C:\Program Files (x86)\LLVM\bin\..\lib\clang\3.7.0\include
c:\Rtools\gcc-4.6.3\lib\gcc\i686-w64-mingw32\4.6.3\include
c:\Rtools\gcc-4.6.3\lib\gcc\i686-w64-mingw32\4.6.3\include-fixed
c:\Rtools\gcc-4.6.3\i686-w64-mingw32\include
c:\Rtools\gcc-4.6.3\include
End of search list.
"c:\\Rtools\\gcc-4.6.3\\bin\\ld.exe" -m i386pe -Bdynamic -o main.exe "c:\\Rtool
s\\gcc-4.6.3\\i686-w64-mingw32\\lib\\crt2.o" "c:\\Rtools\\gcc-4.6.3\\lib\\gcc\\i
686-w64-mingw32\\4.6.3\\crtbegin.o" "-Lc:\\Rtools\\gcc-4.6.3\\lib\\gcc\\i686-w64
-mingw32\\4.6.3" "-Lc:\\Rtools\\gcc-4.6.3\\i686-w64-mingw32\\lib" "-Lc:\\Rtools\
\gcc-4.6.3\\lib" "-Lc:\\Rtools\\gcc-4.6.3\\i686-w64-mingw32/sys-root/mingw/lib"
"C:\\Users\\Bob\\AppData\\Local\\Temp\\main-fdf675.o" -lstdc++ -lmingw32 -lgcc_s
-lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -l
mingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt "c:\\Rtools\\gcc-4.6.3\\lib\
\gcc\\i686-w64-mingw32\\4.6.3\\crtend.o"
c:\Rtools\gcc-4.6.3\bin\ld.exe: cannot find -lgcc_s
c:\Rtools\gcc-4.6.3\bin\ld.exe: cannot find -lgcc_s
clang++.exe: error: linker command failed with exit code 1 (use -v to see invoca
tion)
Related
I am trying to compile a simple helloworld.cpp file using clang on macOS Big Sur.
clang++ -std=c++17 -O3 hello.cpp -v
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1"
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx11.0.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=11.1 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 609.8 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I/usr/local/include -stdlib=libc++ -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include -O3 -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /Users/krumielf/Desktop/Thesis/clang_4life -ferror-limit 19 -fmessage-length 157 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-11.0.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -vectorize-loops -vectorize-slp -o /var/folders/_4/zsjcpnz14xx6_vt850fvg4bw0000gn/T/hello-37932a.o -x c++ hello.cpp
clang -cc1 version 12.0.0 (clang-1200.0.32.29) default target x86_64-apple-darwin20.3.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -dynamic -arch x86_64 -platform_version macos 11.0.0 11.1 -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -o a.out -L/usr/local/lib /var/folders/_4/zsjcpnz14xx6_vt850fvg4bw0000gn/T/hello-37932a.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/lib/darwin/libclang_rt.osx.a
ld: warning: building for macOS, but linking in dylib file (/usr/local/lib/libSystem.dylib) built for DriverKit
ld: cannot link directly with dylib/framework, your binary is not an allowed client of /usr/local/lib/libSystem.dylib for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I have already installed and updated the xcode command line tools. I am not sure on what else to look into and any suggestion will be greatly appreciated.
On my OSX it turns out /usr/local/include is always included as '-I', which caused a lot of headache for me:
hidden$ g++ -v -x c++ -isystem . -c /dev/null -o /dev/null
Apple clang version 11.0.0 (clang-1100.0.33.16)
Target: x86_64-apple-darwin19.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.15.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name null -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=10.15 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -ggnu-pubnames -target-linker-version 530 -v -coverage-notes-file /dev/null.gcno -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0 -isystem . -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -I/usr/local/include -stdlib=libc++ -internal-isystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1 -Wno-framework-include-private-from-public -Wno-atimport-in-framework-header -Wno-extra-semi-stmt -Wno-quoted-include-in-framework-header -fdeprecated-macro -fdebug-compilation-dir /tmp -ferror-limit 19 -fmessage-length 208 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.15.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /dev/null -x c++ /dev/null
clang -cc1 version 11.0.0 (clang-1100.0.33.16) default target x86_64-apple-darwin19.3.0
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
.
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/11.0.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks (framework directory)
End of search list.
The exact headache is not important here, but for anyone who are curious, my protobuf installed at /usr/local/include by Homebrew is used by bazel build, while I want to use my own project's version of protobuf. Bazel adds -isystem for the include paths, which is shown above that is shadowed by -I/usr/local/include.
I tried sudo xcode-select -s /Library/Developer/CommandLineTools but doesn't help.
Anyone knows where the -I/usr/local/include is ever introduced and how I can get rid of it (but not other standard include directories)? Is it some configuration that I can tweak, or is it hard-coded in compiler's binary?
It's provided by Clang itself, by default.
You can supply the -nostdinc/--no-standard-includes to suppress this, but it also suppresses a bunch of other include directories.
A slightly more targeted way is by passing -Xclang -nostdsysteminc, but it still suppresses things you probably want. You can, of course, replace those manually on the command line.
I’m writing some unit tests for a dynamic library on OS X. The dynamic library is in ../MathDll. The library itself is built via the following Makefile:
all: math.dylib
math.dylib: MathDll.cpp MathDll.h
clang -dynamiclib MathDll.cpp -o math.dylib
clean:
rm math.dylib
And running file math.dylib gives
math.dylib: Mach-O 64-bit dynamically linked shared library x86_64
I have a simple program, test1.cpp, that will call one of the functions from this library. I tried to compile it with
clang -I../MathDll -L../MathDll -lmath test1.cpp
but this gives me
ld: library not found for -lmath
clang: error: linker command failed with exit code 1 (use -v to see invocation)
When I invoke Clang with -v, the output is
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.9.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name test1.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 224.1 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0 -I ../MathDll -stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir "/Users/bdesham/Projects/New GUI/math_library/osx_test" -ferror-limit 19 -fmessage-length 118 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/gc/4w1rdgzx3zz2dbxf0m_yd67c0000gn/T/test1-sL5rwc.o -x c++ test1.cpp
clang -cc1 version 5.0 based upon LLVM 3.3svn default target x86_64-apple-darwin13.0.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
../MathDll
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
End of search list.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.9.0 -o a.out -L../MathDll -lmath /var/folders/gc/4w1rdgzx3zz2dbxf0m_yd67c0000gn/T/test1-sL5rwc.o -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.0/lib/darwin/libclang_rt.osx.a
ld: library not found for -lmath
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I must be doing something silly here. What do I need to do to make the linker find my library?
Your library needs to be called libmath.dylib, not just math.dylib.
I am running into a rather hairy compile issue with Clang 3.4. The code compiles just fine with Clang 3.2 but I want to experiment with some bleeding edge features found only on Clang 3.4.
I installed Clang 3.4 by following the instructions here.
Does anyone have a clue as to why Clang is complaining about stdlib.h? I am using Lubuntu 13.04.
Output from Clang 3.2 -
clang -v -g -fsanitize=address -fno-omit-frame-pointer -fms-extensions -O0 -o obj/Test.o -Iinc/ -c Test.c
Ubuntu clang version 3.2-1~exp9ubuntu1 (tags/RELEASE_32/final) (based on LLVM 3.2)
Target: i386-pc-linux-gnu
Thread model: posix
"/usr/bin/clang" -cc1 -triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name Test.c -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu pentium4 -target-linker-version 2.23.2 -momit-leaf-frame-pointer -v -g -coverage-file /home/adminuser/project/obj/Test.o -resource-dir /usr/bin/../lib/clang/3.2 -I inc/ -fmodule-cache-path /var/tmp/clang-module-cache -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.2/include -internal-isystem /usr/include/clang/3.2/include/ -internal-externc-isystem /usr/include/i386-linux-gnu -internal-externc-isystem /usr/include/i686-linux-gnu -internal-externc-isystem /usr/include -O0 -fdebug-compilation-dir /home/adminuser/project -ferror-limit 19 -fmessage-length 0 -fsanitize=address -mstackrealign -fms-extensions -fmsc-version=1300 -fobjc-runtime=gcc -fdiagnostics-show-option -o obj/Test.o -x c Test.c
clang -cc1 version 3.2 based upon LLVM 3.2svn default target i386-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/clang/3.2/include"
ignoring nonexistent directory "/usr/include/i686-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
inc
/usr/local/include
/usr/include/clang/3.2/include
/usr/include/i386-linux-gnu
/usr/include
Output from Clang 3.4 -
clang -v -g -fsanitize=address -fno-omit-frame-pointer -fms-extensions -O0 -o obj/Test.o -Iinc/ Test.c
Ubuntu clang version 3.4-1~exp1 (trunk) (based on LLVM 3.4)
Target: i386-pc-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.7
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.7.3
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.8
Found candidate GCC installation: /usr/bin/../lib/gcc/i686-linux-gnu/4.8.1
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.7
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.7.3
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8
Found candidate GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8.1
Selected GCC installation: /usr/lib/gcc/i686-linux-gnu/4.8
"/usr/bin/clang" -cc1 -triple i386-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name Test.c -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -fuse-init-array -target-cpu pentium4 -target-linker-version 2.23.2 -v -g -coverage-file /home/adminuser/project/obj/Test.o -resource-dir /usr/bin/../lib/clang/3.4 -I inc/ -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/clang/3.4/include -internal-isystem /usr/include/clang/3.4/include/ -internal-externc-isystem /usr/include/i386-linux-gnu -internal-externc-isystem /usr/include/i686-linux-gnu -internal-externc-isystem /usr/include -O0 -fdebug-compilation-dir /home/adminuser/BuildFW/test/GlassCubeAssembler_C -ferror-limit 19 -fmessage-length 0 -fsanitize=address,init-order -mstackrealign -fms-extensions -fmsc-version=1300 -fobjc-runtime=gcc -fobjc-default-synthesize-properties -fdiagnostics-show-option -vectorize-slp -o obj/Test.o -x c Test.c
clang -cc1 version 3.4 based upon LLVM 3.4 default target i386-pc-linux-gnu
ignoring nonexistent directory "/usr/bin/../lib/clang/3.4/include"
ignoring nonexistent directory "/usr/include/i686-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
inc
/usr/local/include
/usr/include/clang/3.4/include
/usr/include/i386-linux-gnu
/usr/include
End of search list.
In file included from Test.c:4:
/usr/include/stdlib.h:69:23: error: expected member name or ';' after declaration specifiers
union wait *__uptr;
~~~~~ ^
1 error generated.
The issue is that you're using -fms-extensions, which enables MS extensions, including a __uptr keyword. Inside stdlib.h, __uptr is used as an identifier:
union wait *__uptr;
... which is incompatible with the MS extension.
Alp Toker has added a workaround for this in clang trunk in upstream r195710, and the fix will be in the Clang 3.4 release.
This was http://llvm.org/PR17824 and was fixed by Alp Toker in Clang r195710: http://llvm.org/viewvc/llvm-project?rev=195710&view=rev
I am trying to build a shared library (dll for Windows) using Clang++.
I have run the following commands:
clang++ -c -o hello.o hello.cpp
clang++ -shared -v -o hello.dll hello.o
The first command works fine but when I try to build the dll I get this error:
clang version 3.2 (tags/RELEASE_32/final)
Target: i686-pc-mingw32
Thread model: posix
"c:/MinGW/bin/g++.exe" -shared -v -m32 -o worker.dll worker.o
Using built-in specs.
COLLECT_GCC=c:/MinGW/bin/g++.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.6.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.6.2 (GCC)
COMPILER_PATH=c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/;c:/mingw/bin/../libexec/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/bin/
LIBRARY_PATH=c:/mingw/bin/../lib/gcc/mingw32/4.6.2/;c:/mingw/bin/../lib/gcc/;c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/lib/;c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../;/mingw/lib/
COLLECT_GCC_OPTIONS='-shared' '-v' '-m32' '-o' 'worker.dll' '-shared-libgcc' '-mtune=i386' '-march=i386'
c:/mingw/bin/../libexec/gcc/mingw32/4.6.2/collect2.exe --shared -Bdynamic -e _DllMainCRTStartup#12 --enable-auto-image-base -u ___register_frame_info -u ___deregister_frame_info -o worker.dll c:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../dllcrt2.o c:/mingw/bin/../lib/gcc/mingw32/4.6.2/crtbegin.o -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.2 -Lc:/mingw/bin/../lib/gcc -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../../mingw32/lib -Lc:/mingw/bin/../lib/gcc/mingw32/4.6.2/../../.. -L/mingw/lib worker.o -lstdc++ -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc_s -lgcc -lmoldname -lmingwex -lmsvcrt c:/mingw/bin/../lib/gcc/mingw32/4.6.2/crtend.o
Cannot export _hello: symbol not found
collect2: ld returned 1 exit status
clang++: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)
Here is the file I am compiling:
// hello.cpp
#include <iostream>
#if defined(_WIN32)
#define LIBRARY_API __declspec(dllexport)
#else
#define LIBRARY_API
#endif
extern "C" void LIBRARY_API hello();
void hello()
{
std::cout << "Hello, World!" << std::endl;
}
A follow up to this important question is that as of clang++ version 6.0, the compilation of a DLL by clang is fine. There are differences for the name mangling of C++ functions in C++ for MSVC and CLang, that can impair the use of DLL's in mixed environments but these differences are easy to spot and correct.