I have clang 3.9 from http://llvm.org/releases/3.9.0/LLVM-3.9.0-win32.exe
clang version 3.9.0 (branches/release_39)
Target: i686-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
And gcc 6.2.0 (Mingw-w64)
gcc (i686-posix-dwarf-rev1, Built by MinGW-W64 project) 6.2.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
I don't have MSVC installed on my PC and no Windows SDK. I need some particular feature of clang and I wanted to replace it with gcc and more specifically with g++ because I use C++.
When I try to compile simple file I get:
fatal error: 'string' file not found
Does it mean my current clang installation doesn't support mingw on windows? Basically all I want is to use headers and libs from my mingw-w64 installation. I was looking for solution and didn't find anything. I don't know what should I do.
Does it also mean my clang installation depends on MSVC that I don't have?
EDIT:
From the comment on this page: http://blog.johannesmp.com/2015/09/01/installing-clang-on-windows-pt2/
This doesn't work anymore with the latest binaries (3.7.1, 3.8, 3.9)
from LLVM, because these were compiled with Visual Studio and for
Visual Studio.
You can install the full Visual Studio 2015 (takes about 8GB) or
install "Microsoft Visual C++ Build Tools 2015 Update 3" which
contains only the command line tools from VS plus the standard C++
header files that Clang needs.
I think it explains everything. Does it mean I need mingw build to get it working with mingw?
The correct thing to do, is this...
clang -target i686-pc-windows-gnu test.c -otest.exe
Or if you want 64bit output...
clang -target x86_64-pc-windows-gnu test.c -otest.exe
Clang will determine the location of the headers and libraries from your path. Make sure that you only have the version of Mingw in your path that you are targetting.
By default, the current release of Clang (5.0.0 as of now) will target x86_64-pc-windows-msvc
By way of example...
Microsoft Windows [Version 10.0.16299.19]
(c) 2017 Microsoft Corporation. All rights reserved.
C:\Users\burito>copy con hello.c
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("Hello World!\n");
return 0;
}
^Z
1 file(s) copied.
C:\Users\burito>clang hello.c -ohello.exe --verbose
clang version 5.0.0 (tags/RELEASE_500/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
clang.exe: warning: unable to find a Visual Studio installation; try running Clang from a developer command prompt [-Wmsvc-not-found]
"C:\\Program Files\\LLVM\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows- msvc18.0.0 -emit-obj -mrelax-all -mincremental-linker-compatible -disable-free - disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation- model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -momit-leaf-frame-pointer -v -dwarf-column-info -debugger-tuning=gdb -resource-dir "C:\\Program Files\\LLVM\\lib\\clang\\5.0.0" -internal-isystem "C:\\Program Files\\LLVM\\lib\\clang\\5.0.0\\include" -internal-isystem C:/Program Files/Microsoft Visual Studio 10.0/VC/include -internal-isystem C:/Program Files/Microsoft Visual Studio 9.0/VC/include -internal-isystem C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include -internal-isystem C:/Program Files/Microsoft Visual Studio 8/VC/include -internal-isystem C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include -fdebug-compilation-dir "C:\\Users\\burito" -ferror-limit 19 -fmessage-length 120 -fms-extensions -fms-compatibility -fms-compatibility-version=18 -fno-threadsafe-statics -fdelayed-template-parsing -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o "C:\\Users\\burito\\AppData\\Local\\Temp\\hello-5c526d.o" -x c hello.c
clang -cc1 version 5.0.0 based upon LLVM 5.0.0 default target x86_64-pc-windows-msvc
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 10.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 9.0/VC/PlatformSDK/Include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/include"
ignoring nonexistent directory "C:/Program Files/Microsoft Visual Studio 8/VC/PlatformSDK/Include"
#include "..." search starts here:
#include <...> search starts here:
C:\Program Files\LLVM\lib\clang\5.0.0\include
End of search list.
hello.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
^~~~~~~~~
1 error generated.
C:\Users\burito>clang hello.c -ohello.exe --verbose -target x86_64-pc-windows-gnu
clang version 5.0.0 (tags/RELEASE_500/final)
Target: x86_64-pc-windows-gnu
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin
"C:\\Program Files\\LLVM\\bin\\clang.exe" -cc1 -triple x86_64-pc-windows-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello.c -mrelocation-model pic -pic-level 2 -mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -target-cpu x86-64 -momit-leaf-frame-pointer -v -dwarf-column-info -debugger-tuning=gdb -resource-dir "C:\\Program Files\\LLVM\\lib\\clang\\5.0.0" -internal-isystem "C:\\Program Files\\LLVM\\lib\\clang\\5.0.0\\include" -internal-isystem "C:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\x86_64-w64-mingw32/sys-root/mingw/include" -internal-isystem "C:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\x86_64-w64-mingw32\\include" -internal-isystem "C:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\include" -fdebug-compilation-dir "C:\\Users\\burito" -ferror-limit 19 -fmessage-length 120 -fno-use-cxa-atexit -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -o "C:\\Users\\burito\\AppData\\Local\\Temp\\hello-d88ba4.o" -x c hello.c
clang -cc1 version 5.0.0 based upon LLVM 5.0.0 default target x86_64-pc-windows-msvc
ignoring nonexistent directory "C:\Program Files\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev0\mingw64\x86_64-w64-mingw32/sys-root/mingw/include"
#include "..." search starts here:
#include <...> search starts here:
C:\Program Files\LLVM\lib\clang\5.0.0\include
C:\Program Files\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev0\mingw64\x86_64-w64-mingw32\include
C:\Program Files\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev0\mingw64\include
End of search list.
"C:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\bin\\ld.exe" -m i386pep -Bdynamic -o hello.exe "C:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\x86_64-w64-mingw32\\lib\\crt2.o" "C:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\7.2.0\\crtbegin.o" "-LC:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\7.2.0" "-LC:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\x86_64-w64-mingw32\\lib" "-LC:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\lib" "-LC:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\x86_64-w64-mingw32/sys-root/mingw/lib" "C:\\Users\\burito\\AppData\\Local\\Temp\\hello-d88ba4.o" -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt -ladvapi32 -lshell32 -luser32 -lkernel32 -lmingw32 -lgcc -lgcc_eh -lmoldname -lmingwex -lmsvcrt "C:\\Program Files\\mingw-w64\\x86_64-7.2.0-posix-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\7.2.0\\crtend.o"
C:\Users\burito>hello
Hello World!
C:\Users\burito>
After installing older version built with MinGW that is 3.7.0 RC3 it worked.
You can notice the difference in version i686-pc-windows-gnu vs i686-pc-windows-msvc.
I think clang 3.9 would work too if they didn't break something in their source code and if you'd build it yourself. Would be nice to have newest 3.9 working with MinGW too. I'm too lazy though to try to build it myself.
EDIT:
There are some packages for mingw too https://github.com/Alexpux/MINGW-packages that you can install using MSYS2 that seem to provide support for clang. There are some commits related to 3.8 and 3.9.
Hope this will help someone that has similar problems.
Related
Clang isn't able to find omp.h whenever I try to compile with openMP flag. Here's what I'm trying to do
clang++ -dynamiclib -I/opt/homebrew/Cellar/eigen/3.3.9/include/eigen3/ -Xpreprocessor -fopenmp -o libfoo.dylib foolibrary.cpp -lomp
Although I have omp.h in /opt/homebrew/Cellar/libomp/11.0.1/include/omp.h, while clang is in usr/bin/clang. Is there anything I need to configure so that it's able to find it?
When using brew to target the M1 natively, the brew installed clang is not in /usr/bin.
The brew instructions show that the preferred location for it is /opt/homebrew. The clang in /usr/bin is a link to the Apple command line tools one; you can see that by using -v.
$ /usr/bin/clang -v
/usr/bin/clang -v
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: arm64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
To get the brew installed clang you need to follow the instructions brew gave you when you installed it :-
llvm is keg-only, which means it was not symlinked into /opt/homebrew,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have llvm first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.profile
For compilers to find llvm you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/llvm/lib"
export CPPFLAGS="-I/opt/homebrew/opt/llvm/include"
Doing that resolves the include issue, but, at least for me, not the library linking one.
/opt/homebrew/opt/llvm/bin/clang -v -fopenmp hello_omp.c
clang version 11.1.0
Target: arm64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /opt/homebrew/opt/llvm/bin
"/opt/homebrew/Cellar/llvm/11.1.0/bin/clang-11" -cc1 -triple arm64-apple-macosx11.0.0 -Wundef-prefix=TARGET_OS_ -Werror=undef-prefix -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name hello_omp.c -mrelocation-model pic -pic-level 2 -mframe-pointer=non-leaf -fno-rounding-math -munwind-tables -fcompatibility-qualified-id-block-type-checking -target-cpu apple-a7 -target-feature +fp-armv8 -target-feature +neon -target-feature +crypto -target-feature +zcm -target-feature +zcz -target-feature +sha2 -target-feature +aes -target-abi darwinpcs -fallow-half-arguments-and-returns -debugger-tuning=lldb -target-linker-version 609.8 -v -resource-dir /opt/homebrew/Cellar/llvm/11.1.0/lib/clang/11.1.0 -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -internal-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include -internal-isystem /opt/homebrew/Cellar/llvm/11.1.0/lib/clang/11.1.0/include -internal-externc-isystem /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include -fdebug-compilation-dir /Users/jcownie/tmp -ferror-limit 19 -fmessage-length=163 -fopenmp -fopenmp-cuda-parallel-target-regions -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fmax-type-align=16 -o /var/folders/lt/nf3dtk8j16qfsl97d_vgv4dw000lts/T/hello_omp-bd4ce3.o -x c hello_omp.c
clang -cc1 version 11.1.0 based upon LLVM 11.1.0 default target arm64-apple-darwin20.3.0
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/local/include"
ignoring nonexistent directory "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/opt/homebrew/Cellar/llvm/11.1.0/lib/clang/11.1.0/include
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include
/Library/Developer/CommandLineTools/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 /opt/homebrew/Cellar/llvm/11.1.0/lib/libLTO.dylib -no_deduplicate -dynamic -arch arm64 -platform_version macos 11.0.0 0.0.0 -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk -o a.out /var/folders/lt/nf3dtk8j16qfsl97d_vgv4dw000lts/T/hello_omp-bd4ce3.o -lomp -lSystem /opt/homebrew/Cellar/llvm/11.1.0/lib/clang/11.1.0/lib/darwin/libclang_rt.osx.a
ld: library not found for -lomp
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
If you explicitly pass the recommended $LDFLAGS, then things work...
$ echo $LDFLAGS
-L/opt/homebrew/opt/llvm/lib
$ /opt/homebrew/opt/llvm/bin/clang $LDFLAGS -fopenmp hello_omp.c
/opt/homebrew/opt/llvm/bin/clang $LDFLAGS -fopenmp hello_omp.c
$ ./a.out
./a.out
Hello from thread 0
Hello from thread 5
Hello from thread 4
Hello from thread 1
Hello from thread 3
Hello from thread 2
Hello from thread 7
Hello from thread 6
$
My (hacky, but it works) solution to that has been to create my own shell scripts to invoke the compilers with the appropriate library path; you can see this hack in How to build LLVM (clang,clang++) for Apple M1?
Note that at one more point the support for OpenMP tasks was broken in LLVM when targeting the M1. (See "Crash in passing firstprivate args to tasks on Apple M1"). However, that was fixed in March 2021, so be sure to use a more recent LLVM release.
In your terminal:
brew install libomp
Then in your Makefile:
CC=clang++
FLAGS=-g -Wall -std=c++17 -arch arm64 -lomp
LDFLAGS=-L/opt/homebrew/lib
CPPFLAGS=-I/opt/homebrew/include
My Mac & clang:
clang -v
Apple clang version 13.1.6 (clang-1316.0.21.2.5)
Target: arm64-apple-darwin21.5.0
Thread model: posix
I am trying to build some fairly simple c++ code that relies on SDL2. Although I have xcode installed, I am invoking clang from the command line and not using xcode.
The SDL2 framework is located under /Library/Frameworks/SDL2.framework (note that although I reference SDL2 in my post, this problem is not SDL2 specific.)
To pull in the SDL2 dependencies, I specify the SDL2 framework to clang like so:
clang -std=c++11 -framework SDL2 test.cpp
However when I do this, the SDL headers I include (for example #include <SDL2/SDL.h>) can't be located. If I pass /Library/Frameworks as a framework search path to clang like so:
clang -std=c++11 -F/Library/Frameworks/ -framework SDL2 test.cpp
... then everything works. So I can get by. But based on various makefiles I've found around in sample projects, it seems that on Mac OS, the /System/Library/Frameworks and /Library/Frameworks paths are expected to be part of the default set of search paths that clang uses to locate frameworks. This does not seem to be the case for me. If I compare my include paths with what's reported in this blog post, then I'm clearly missing /Library/Frameworks and /System/Library/Frameworks.
Output of clang -x c -v -E /dev/null:
Apple LLVM version 10.0.1 (clang-1001.0.46.4)
Target: x86_64-apple-darwin18.6.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.14.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -E -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.14 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 450.3 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I/usr/local/include -Wno-atomic-implicit-seq-cst -Wno-framework-include-private-from-public -Wno-atimport-in-framework-header -Wno-quoted-include-in-framework-header -fdebug-compilation-dir -ferror-limit 19 -fmessage-length 0 -stack-protector 1 -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fobjc-runtime=macosx-10.14.0 -fmax-type-align=16 -fdiagnostics-show-option -o - -x c /dev/null
clang -cc1 version 10.0.1 (clang-1001.0.46.4) default target x86_64-apple-darwin18.6.0
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/10.0.1/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks (framework directory)
Output of clang -Xlinker -v:
#(#)PROGRAM:ld PROJECT:ld64-450.3
BUILD 18:16:53 Apr 5 2019
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
Library search paths:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/lib
Framework search paths:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/
I haven't found how to globally specify additional framework paths for clang, but I'm not sure if that's something that's meant to be configured externally or built-in the clang binaries. I do have a workaround, but like I said, based on samples I see on the web, it feels like the expected behaviour would be to have those additional framework include paths somehow included by default.
It doesn't help that combining "framework" to any google search dilutes the real intent of my query.
Any idea what I might be doing wrong, or what I should look for?
Cheers.
Two things:
SDL2 is not a standard Framework (and)
macOS looks for Frameworks in (as shown in the output "Framework search paths"):
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/ \
Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/
If you want don't want to use -L then you'll probably want copy the framework there.
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)
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