Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Here is the kind of errors I get, that is definitely not related to my code
/usr/bin/c++ -D_TIMER -g -I/usr/local/Cellar/boost/1.54.0/include -I/Users/issam/include -o output.o -c project.cpp
In file included from project.cpp:756:
In file included from /Users/issam/include/project.hpp:123:
In file included from /usr/local/Cellar/boost/1.54.0/include/boost/regex.hpp:31:
In file included from /usr/local/Cellar/boost/1.54.0/include/boost/regex/v4/regex.hpp:39:
In file included from /usr/local/Cellar/boost/1.54.0/include/boost/regex/regex_traits.hpp:27:
In file included from /usr/local/Cellar/boost/1.54.0/include/boost/regex/v4/regex_traits.hpp:39:
In file included from /usr/local/Cellar/boost/1.54.0/include/boost/regex/v4/cpp_regex_traits.hpp:40:
/usr/local/Cellar/boost/1.54.0/include/boost/regex/pending/object_cache.hpp:39:17: error: no type named 'list' in namespace 'std'
typedef std::list<value_type> list_type;
~~~~~^
if I compile a file that only includes:
#include "boost/regex.hpp"
It compiles without any problem and creates the .o file. Here is the verbose output of the compilation
/usr/bin/c++ -D_TIMER -g -I/usr/local/Cellar/boost/1.54.0/include -o output.o -c newFile.cpp -v
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
"/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name newFile.cpp -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 136 -v -g -coverage-file /Users/issam/folder/output.o -resource-dir /usr/bin/../lib/clang/4.2 -D _TIMER -I /usr/local/Cellar/boost/1.54.0/include -fmodule-cache-path /var/folders/pd/kcfk19hd5mv9vjwsvpqtk_tc0000gq/T/clang-module-cache -fdeprecated-macro -fdebug-compilation-dir /Users/issam/folder -ferror-limit 19 -fmessage-length 168 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.8.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o output.o -x c++ newFile.cpp
clang -cc1 version 4.2 based upon LLVM 3.2svn default target x86_64-apple-darwin12.5.0
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64"
ignoring nonexistent directory "/usr/include/c++/4.0.0"
ignoring nonexistent directory "/usr/include/c++/4.0.0/i686-apple-darwin8/"
ignoring nonexistent directory "/usr/include/c++/4.0.0/backward"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/Cellar/boost/1.54.0/include
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/usr/local/include
/usr/bin/../lib/clang/4.2/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
boost/regex/pending/object_cache.hpp has the following on line 23:
#include <list>
so for an error such as "error: no type named 'list' in namespace 'std'", it seems likely that your installation of Boost or your compiler toolchain has a problem.
What happens if you try to compile a C++ source file that contains only:
#include "boost/regex.hpp"
I looked it up - the mentioned header file includes <list>, so everything is ok there.
Chances are that you messed up the namespaces by including either boost/regex.hpp or your own project.hpp inside a namespace or by using directives before the #include of either header.
The compiler tells you about an error at the location where it actually sees there was an error, in this case somewhere deep in the guts of the boost headers. Often, when an error is made, you don't notice it immediately, but much later when things look screwed up. It's the same for the compiler this time. It can't say exactly where you messed up, but only how it knows something is wrong.
Related
I'm on a project where I need to use libc++. I'm come up with the following problem:
When I try to compile the following code:
#include <string>
int main()
{
std::string::size_type (std::string::*function)() const = &std::string::size;
return 0;
}
I get the following error:
ld: symbol(s) not found for architecture x86_64
If I use the libstdc++ instead of libc++ I get no errors so the issue should to be related with libc++.
Full output below:
clang++ --stdlib=libc++ -v main.cpp
Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.10.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 241.9 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0 --stdlib=libc++ -fdeprecated-macro -fdebug-compilation-dir /Users/filipe/Downloads -ferror-limit 19 -fmessage-length 197 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.10.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/folders/8k/34ll5dcj3c5c9sph_bwk1zr00000gn/T/main-5b89bb.o -x c++ main.cpp
clang -cc1 version 6.0 based upon LLVM 3.5svn default target x86_64-apple-darwin14.1.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.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.10.0 -o a.out /var/folders/8k/34ll5dcj3c5c9sph_bwk1zr00000gn/T/main-5b89bb.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::size() const", referenced from:
_main in main-5b89bb.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This looks like a libc++ bug by this thread: _LIBCPP_INLINE_VISIBILITY and std::string::length which doing something similar and Howard Hinnant's response is:
I believe this is due to a poor interaction in the compiler between
extern templates and __attribute__ ((__always_inline__)). If
std::string is not declared extern template, then the compiler will
outline a size() member and you won't get this link error.
In my opinion, clang should not assume that extern templates have
definitions for inlined members, especially those marked
always_inline, and the fact that it does is a clang bug resulting in
the link error you see.
The rationale for the use of always_inline in libc++ is to control the
ABI of libc++. In the past I have watched compilers use different
heuristics from release to release on making the inline/outline
decision. This can cause code to be silently added to and removed
from a dylib. With the use of always_inline, I am telling the
compiler to never add that code to the libc++.dylib binary.
Each of the macros defined and used by libc++ can be overridden.
_LIBCPP_INLINE_VISIBILITY controls how an inlined function is attributed and defaults to:
#ifndef _LIBCPP_INLINE_VISIBILITY
#define _LIBCPP_INLINE_VISIBILITY __attribute__ ((__visibility__("hidden"), __always_inline__))
#endif
You can turn this off with:
-D_LIBCPP_INLINE_VISIBILITY=""
And extern templates are done with:
#ifndef _LIBCPP_EXTERN_TEMPLATE
#define _LIBCPP_EXTERN_TEMPLATE(...) extern template __VA_ARGS__;
#endif
This latter one is more difficult to "turn off". The incantation is:
-D'_LIBCPP_EXTERN_TEMPLATE(...)='
Using either (or both) of these workarounds will silence your link
error. But a bug report against clang might be a better long term
solution.
I can not reproduce this on coliru but I can on wandbox and using optimization which uses the -O2 flag makes the problem go away. I was not able to make wandbox accept the -D options suggested above, so not sure if that works.
On my local machine Howard's solution works:
clang++ -D_LIBCPP_INLINE_VISIBILITY="" -D'_LIBCPP_EXTERN_TEMPLATE(...)='
I have not found a bug report, if I don't find one it may make sense to file one.
After looking into Shafik Yaghmour information, I found a solution that doesn't require modifying the compilation flags.
The solution is forcing the compiler to instantiate the extern template class. The final code is the following:
#include <string>
template class std::basic_string<char>;
int main()
{
std::string::size_type (std::string::*function)() const = &std::string::size;
return 0;
}
More information here: using extern template (C++11)
I have the following program:
#include <stdio.h>
int bob() {
printf("bob\n");
return 0;
}
int main() {
printf("main\n");
return 0;
}
On Linux, I can enable a custom entry point via:
gcc test.c -Wl,-e,bob
When I run the resulting program, I get:
./a.out
bob
On OS X, however, this doesn't work:
clang test.c -Wl,-e,bob
./a.out
main
I've tried everything to get this to work. I think it might be a bug. Here's the output with the -v option:
clang test.c -Wl,-e,bob -v
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.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 test.c -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 236.3 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1 -fdebug-compilation-dir /Users/mfichman/jogo -ferror-limit 19 -fmessage-length 125 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.9.0 -fencode-extended-block-signature -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o /var/folders/4z/q41by0256hjc7s6v8ljmfpw8lywh5g/T/test-9b80a6.o -x c test.c
clang -cc1 version 5.1 based upon LLVM 3.4svn default target x86_64-apple-darwin13.3.0
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/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 -e bob -o a.out /var/folders/4z/q41by0256hjc7s6v8ljmfpw8lywh5g/T/test-9b80a6.o -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/5.1/lib/darwin/libclang_rt.osx.a
You can see that clang is correctly passing -e to ld, so maybe this is a problem with Apple's ld. If that's the case, I'd be interested in workaround solutions.
The default entry point overridden by the -e argument is not _main but rather start, which is responsible for setting up and calling _main, then passing the return value of _main to _exit. If you specify your own entry point you'll need to perform these steps yourself. There's currently no way to have this initialization performed for you but use a different main function as use of _main is hard-coded into the tools.
The reason your -e argument is ignored is due to a change in 10.8. Prior to this release the implementation of start was linked into each application via crt1.o. In 10.8 the start processing can be performed by dyld and the LC_MAIN load command specifies the offset to the main function within the program. Changing this offset appears to be what you want, but this is not currently possible as when the LC_MAIN startup method is used ld always uses _main and disregards the -e argument. To specify your own entry point you need to tell ld to use the old method of program startup, which you can do for an application with a deployment target of 10.8 or later by passing -no_new_main to the linker. This is the default behavior for applications with a deployment target earlier than 10.8.
so I think I've done something really stupid and I just can't figure this out. The following program is causing me a lot of pain:
#include <iostream>
int time = 0;
int main(int argc, char **argv) {
std::cout << "hi" << std::endl;
return 0;
}
My compile string is: clang++ -std=c++1y --verbose -stdlib=libc++ main.cpp -o main. The redefinition error is /usr/include/time.h:116:8: note: previous definition is here and the --verbose shows me this as the include path order:
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
"/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.10.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 241.9 -v -resource-dir /Library/Developer/CommandLineTools/usr/bin/../lib/clang/6.0 -stdlib=libc++ -std=c++1y -fdeprecated-macro -fdebug-compilation-dir /Users/aliak/dev/atom/sim -ferror-limit 19 -fmessage-length 0 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.10.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-slp -o /var/folders/r_/pmd7rtcd4h35dqsf496nyzsh0000gn/T/main-d500bd.o -x c++ /Users/aliak/dev/atom/sim/main.cpp
clang -cc1 version 6.0 based upon LLVM 3.5svn default target x86_64-apple-darwin14.1.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
/usr/local/include
/Library/Developer/CommandLineTools/usr/bin/../lib/clang/6.0/include
/Library/Developer/CommandLineTools/usr/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
I just can't figure out what's wrong. If I add in -nostdinc++ to the command line args to clang and then remove the iostream include, but keep the time var, it's all ok. Which I guess means the iostream is including time.h. But I am quite confused, should it not include ctime instead of time.h, which would wrap everything in the std namespace?
I've tried deleting xcode and reinstalling as well.
Update:
The comment from Mats made me do a little bit more snooping. So passing in -H to clang++ prints out the header tree. And it turns out that pthread.h is the one actually including time.h. But ctime also actually includes time.h. And this seems according to the standard because: "In the C++ standard library, however, the declarations (except for names which are defined as macros in C) are within namespace scope (3.3.6) of the namespace std. It is unspecified whether these names are first declared within the global namespace scope and are then injected into namespace std by explicit using-declarations"
time() is a function in standard C, which means that it's living outside a namespace so that "old" C code can be compiled with C++ compilers without having lots of using namespace std thrown in all over the place.
The header time.h is apparently included when you include <iostream>, which is why you get a reference to that.
Either don't use that name, or add namespace MyName { int time; }; and then use MyName::time when you want to refer to your variable.
[I don't know the exact place, but I beleive the C++ standard states that "existing standard library functions may or may not exist outside of the std:: namespace when you include for example <ctime> - the actual implementation of <ctime> does almost certainly include regular <time.h> somewhere.]
For example in the g++ 4.9.2 headers on my linux box:
....
#pragma GCC system_header
#include <bits/c++config.h>
#include <time.h>
#ifndef _GLIBCXX_CTIME
#define _GLIBCXX_CTIME 1
...
namespace std
{
...
using ::time;
...
} // namespace
The one in libcxx looks almost identical.
I just to change the include search path order (I believe).
I'd like to change the include search path. Especially, I need /usr/local/include first.
But it doesn't change because of duplicate. How can I change it?
I suppose there's default setting, because paths I don't specify appears. Like /usr/include/c++/4.2.1, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.10.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name test_common.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 241.9 -v -gdwarf-2 -coverage-file /Users/machidahiroaki/RubymineProjects/caffe/.build_debug/src/caffe/test/test_common.o -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0 -D DEBUG -D CPU_ONLY -I /usr/local/include -I /usr/local/include -I /Users/machidahiroaki/anaconda/include -I /Users/machidahiroaki/anaconda/include/python2.7 -I /Users/machidahiroaki/anaconda/lib/python2.7/site-packages/numpy/core/include -I .build_debug/src -I ./src -I ./include -I /usr/local/atlas/include -stdlib=libstdc++ -O0 -Wall -Wno-sign-compare -Wno-unneeded-internal-declaration -fdeprecated-macro -fdebug-compilation-dir /Users/machidahiroaki/RubymineProjects/caffe -ferror-limit 19 -fmessage-length 0 -pthread -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.10.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option -vectorize-slp -o .build_debug/src/caffe/test/test_common.o -x c++ src/caffe/test/test_common.cpp
clang -cc1 version 6.0 based upon LLVM 3.5svn default target x86_64-apple-darwin14.0.0
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin10/x86_64"
ignoring nonexistent directory "/usr/include/c++/4.0.0"
ignoring nonexistent directory "/usr/include/c++/4.0.0/i686-apple-darwin8/"
ignoring nonexistent directory "/usr/include/c++/4.0.0/backward"
ignoring duplicate directory "/usr/local/include"
ignoring duplicate directory "/usr/local/include"
as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
/Users/machidahiroaki/anaconda/include
/Users/machidahiroaki/anaconda/include/python2.7
/Users/machidahiroaki/anaconda/lib/python2.7/site-packages/numpy/core/include
.build_debug/src
./src
./include
/usr/local/atlas/include
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.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.
Library search paths
Machida-no-MacBook-Air:caffe machidahiroaki$ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld -v ...
#(#)PROGRAM:ld PROJECT:ld64-241.9
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7m armv7em
Library search paths:
/usr/lib
/usr/local/lib
Framework search paths:
/Library/Frameworks/
/System/Library/Frameworks/
For sure this is the ld done in make.
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -dylib -arch x86_64 -macosx_version_min 10.10.0 -t -o .build_debug/lib/libcaffe.so -L/usr/local/lib -L/usr/lib -L/usr/local/atlas/lib .build_debug/src/caffe/proto/caffe.pb.o .build_debug/src/caffe/proto/caffe_pretty_print.pb.o .build_debug/src/caffe/blob.o .build_debug/src/caffe/common.o .build_debug/src/caffe/data_transformer.o .build_debug/src/caffe/internal_thread.o .build_debug/src/caffe/layer_factory.o .build_debug/src/caffe/layers/absval_layer.o .build_debug/src/caffe/layers/accuracy_layer.o .build_debug/src/caffe/layers/argmax_layer.o .build_debug/src/caffe/layers/base_data_layer.o .build_debug/src/caffe/layers/bnll_layer.o .build_debug/src/caffe/layers/concat_layer.o .build_debug/src/caffe/layers/contrastive_loss_layer.o .build_debug/src/caffe/layers/conv_layer.o .build_debug/src/caffe/layers/cudnn_conv_layer.o .build_debug/src/caffe/layers/cudnn_pooling_layer.o .build_debug/src/caffe/layers/cudnn_relu_layer.o .build_debug/src/caffe/layers/cudnn_sigmoid_layer.o .build_debug/src/caffe/layers/cudnn_softmax_layer.o .build_debug/src/caffe/layers/cudnn_tanh_layer.o .build_debug/src/caffe/layers/data_layer.o .build_debug/src/caffe/layers/dropout_layer.o .build_debug/src/caffe/layers/dummy_data_layer.o .build_debug/src/caffe/layers/eltwise_layer.o .build_debug/src/caffe/layers/euclidean_loss_layer.o .build_debug/src/caffe/layers/flatten_layer.o .build_debug/src/caffe/layers/hdf5_data_layer.o .build_debug/src/caffe/layers/hdf5_output_layer.o .build_debug/src/caffe/layers/hinge_loss_layer.o .build_debug/src/caffe/layers/im2col_layer.o .build_debug/src/caffe/layers/image_data_layer.o .build_debug/src/caffe/layers/infogain_loss_layer.o .build_debug/src/caffe/layers/inner_product_layer.o .build_debug/src/caffe/layers/loss_layer.o .build_debug/src/caffe/layers/lrn_layer.o .build_debug/src/caffe/layers/memory_data_layer.o .build_debug/src/caffe/layers/multinomial_logistic_loss_layer.o .build_debug/src/caffe/layers/mvn_layer.o .build_debug/src/caffe/layers/neuron_layer.o .build_debug/src/caffe/layers/pooling_layer.o .build_debug/src/caffe/layers/power_layer.o .build_debug/src/caffe/layers/relu_layer.o .build_debug/src/caffe/layers/sigmoid_cross_entropy_loss_layer.o .build_debug/src/caffe/layers/sigmoid_layer.o .build_debug/src/caffe/layers/silence_layer.o .build_debug/src/caffe/layers/slice_layer.o .build_debug/src/caffe/layers/softmax_layer.o .build_debug/src/caffe/layers/softmax_loss_layer.o .build_debug/src/caffe/layers/split_layer.o .build_debug/src/caffe/layers/tanh_layer.o .build_debug/src/caffe/layers/threshold_layer.o .build_debug/src/caffe/layers/window_data_layer.o .build_debug/src/caffe/net.o .build_debug/src/caffe/solver.o .build_debug/src/caffe/syncedmem.o .build_debug/src/caffe/util/benchmark.o .build_debug/src/caffe/util/im2col.o .build_debug/src/caffe/util/insert_splits.o .build_debug/src/caffe/util/io.o .build_debug/src/caffe/util/math_functions.o .build_debug/src/caffe/util/upgrade_proto.o -framework Accelerate -lglog -lgflags -lprotobuf -lleveldb -lsnappy -llmdb -lboost_system -lhdf5_hl -lhdf5 -lopencv_core -lopencv_highgui -lopencv_imgproc -lpthread -lboost_thread-mt -lcblas -lstdc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/lib/darwin/libclang_rt.osx.a
So... where does this path /usr/include/c++/4.2.1 come from?
Did I get some hints?
Machida-no-MacBook-Air:caffe machidahiroaki$ g++ -print-search-dirs
install: /usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/
programs: =/usr/local/libexec/gcc/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/libexec/gcc/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/libexec/gcc/x86_64-apple-darwin14.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../../x86_64-apple-darwin14.0.0/bin/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../../x86_64-apple-darwin14.0.0/bin/
libraries: =/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../../x86_64-apple-darwin14.0.0/lib/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../../x86_64-apple-darwin14.0.0/lib/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../:/lib/x86_64-apple-darwin14.0.0/5.0.0/:/lib/:/usr/lib/x86_64-apple-darwin14.0.0/5.0.0/:/usr/lib/
Machida-no-MacBook-Air:caffe machidahiroaki$ clang++ -print-search-dirs
programs: =/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
libraries: =/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0
M
I don't know if it has to do with the problem...
Machida-no-MacBook-Air:caffe machidahiroaki$ gcc -print-search-dirs
install: /usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/
programs: =/usr/local/libexec/gcc/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/libexec/gcc/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/libexec/gcc/x86_64-apple-darwin14.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../../x86_64-apple-darwin14.0.0/bin/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../../x86_64-apple-darwin14.0.0/bin/
libraries: =/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../../x86_64-apple-darwin14.0.0/lib/x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../../x86_64-apple-darwin14.0.0/lib/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../x86_64-apple-darwin14.0.0/5.0.0/:/usr/local/lib/gcc/x86_64-apple-darwin14.0.0/5.0.0/../../../:/lib/x86_64-apple-darwin14.0.0/5.0.0/:/lib/:/usr/lib/x86_64-apple-darwin14.0.0/5.0.0/:/usr/lib/
Machida-no-MacBook-Air:caffe machidahiroaki$ gcc --version
gcc (GCC) 5.0.0 20141005 (experimental)
Copyright (C) 2014 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.
Wait, export CFLAGS="-I/path/to/preferred/HDF5/hdf5.h" would not work...
Specify nothing
Machida-no-MacBook-Air:caffe machidahiroaki$ echo | "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -Wp,-v -stdlib=libstdc++ -x c++ - -fsyntax-only
clang -cc1 version 6.0 based upon LLVM 3.5svn default target x86_64-apple-darwin14.0.0
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.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.
Can't specify a header file!!
Machida-no-MacBook-Air:caffe machidahiroaki$ echo | "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -Wp,-v -stdlib=libstdc++ -x c++ - -fsyntax-only -I/usr/local/include/hdf5.h
clang -cc1 version 6.0 based upon LLVM 3.5svn default target x86_64-apple-darwin14.0.0
ignoring nonexistent directory "/usr/local/include/hdf5.h"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.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.
As expected, the duplicate directory is ignored and the order does not change.
Machida-no-MacBook-Air:caffe machidahiroaki$ echo | "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -Wp,-v -stdlib=libstdc++ -x c++ - -fsyntax-only -I/usr/local/include/
clang -cc1 version 6.0 based upon LLVM 3.5svn default target x86_64-apple-darwin14.0.0
ignoring duplicate directory "/usr/local/include"
as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/usr/local/include
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.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.
But, I found clang's -include option, which is able to specify a file!
I'd like to change library search path...
At compile time, you augment the library search path with -L. You cannot delete paths; you can only add paths that have a "higher" preference than existing paths.
At runtime, you use DYLD_LIBRARY_PATH, DYLD_FALLBACK_LIBRARY_PATH and friends to change the library search path. See dyld(1) OS X Man Pages.
Usually you use DYLD_LIBRARY_PATH to ensure a particular library is loaded rather than the system one. Its a way to override default behavior. DYLD_FALLBACK_LIBRARY_PATH is used to provide a library that's not a system one. Its less intrusive because you don't displace system paths.
----------
I need /usr/local/include first...
Sounds a bit odd to me, but...
$ export DYLD_LIBRARY_PATH=/usr/local/include
$ clang ...
----------
IF you are cross-compiling from the command line, you should do something like this. The trick is to use --sysroot to automatically bring in the headers and libraries for the platform, rather than hacking them with -I, -L and -l.
# Put cross compile tools on the PATH first
export PATH="/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/:$PATH"
# C compiler
export CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
# C++ compiler
export CXX=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++
# SYSROOT brings in platform headers and libraries, No need for -I, -L and -l.
SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk
# Compiler flags
export CFLAGS="-march armv7 -march armv7s --sysroot=$SYSROOT"
# Compiler flags
export CXXFLAGS="-march armv7 -march armv7s --sysroot=$SYSROOT"
# Using defualt C++ runtime
$CXX $CXXFLAGS foo.c -o foo.exe
You can also specify GNU's runtime with -stdlib=libstdc++, and LLVM's runtime with -stdlib=libc++.
----------
Based on your updates:
<ld command and output omitted>
where does this path /usr/include/c++/4.2.1 come from??
/usr/include/c++/4.2.1 is not in your Library Search Path. Its just not there.
That's a header include path, and you specify it with -I.
If you want to see your header include paths for libstdc++ and libc++, do this:
# GNU C++ runtime
$ echo | /usr/local/bin/clang++ -Wp,-v -stdlib=ibstdc++ -x c++ - -fsyntax-only
And:
# LLVM C++ runtime
$ echo | /usr/local/bin/clang++ -Wp,-v -stdlib=libc++ -x c++ - -fsyntax-only
Here's what I get on OS X 10.8.5:
libstdc++ (GNU):
/usr/include/c++/4.2.1
/usr/include/c++/4.2.1/backward
/usr/local/include
/usr/local/bin/../lib/clang/3.5.0/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory
libc++ (LLVM):
/usr/local/include
/usr/local/bin/../lib/clang/3.5.0/include
/usr/include
/System/Library/Frameworks (framework directory)
/Library/Frameworks (framework directory)
So /usr/include/c++/4.2.1 is a built-in compiler path when using GNU's libstdc++ (but not LLVM's libc++). I'll go even further and tell you its hard coded in LLVM/Clang sources (I build LLVM/Clang from source often):
$ cd clang-sources/llvm
$ grep -R "/usr/include/c++/4.2.1" *
tools/clang/lib/Frontend/InitHeaderSearch.cpp: AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
tools/clang/lib/Frontend/InitHeaderSearch.cpp: AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
tools/clang/lib/Frontend/InitHeaderSearch.cpp: AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
tools/clang/lib/Frontend/InitHeaderSearch.cpp: AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
tools/clang/lib/Frontend/InitHeaderSearch.cpp: AddGnuCPlusPlusIncludePaths("/usr/include/c++/4.2.1",
You can add additional include paths when building LLVM/Clang with --with-c-include-dirs.
----------
Based on your comment: "... If I delete ~/anaconda/include/hdf5.h...". If you need a new path for the HDF5 package, then use something like:
export CPPFLAGS="-I/path/to/preferred/HDF5/hdf5.h"
export CFLAGS="-I/path/to/preferred/HDF5/hdf5.h"
export CXXFLAGS="-I/path/to/preferred/HDF5/hdf5.h"
export LDFLAGS="-L/path/to/preferred/HDF5/lib"
./configure ...
You need it in CPPFLAGS too because the autotools might run some tests with it.
Then, at runtime:
export DYLD_LIBRARY_PATH=/path/to/preferred/HDF5/lib
./run_the_executable
And you can side step DYLD_LIBRARY_PATH IF you perform static linking against HDF5. But be aware the OS X linker always uses a shared object or dynalib if its available. Effectively, it ignores your request for static linking. You will have to mv shared object or dynalib off-path while leaving an archive on-path.
----------
To muddy the waters a little more... If you are saying "library" when you really want to say "framework", then see this Stack Overflow question about using the -framework option: Clang(LLVM) compile with frameworks.
You can go into your project settings and make changes to edit your library search paths very easily.
See how I opened up the settings in this test project screenshot? There's no paths in my own project there right now; but in your project, there will certainly be duplicate paths (or multiple paths that resolve to the same place).
Open Terminal
Run gcc -V
Read the information and copy the include path. Mine is
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/c++/4.2.1
while compiling in our test environment i encountered the following problem:
Despite the already working windows our build failed on Freebsd 9 with the following error message:
error: no member named 'all_of' in namespace 'std'
Given that i added -std=c++11 to our Cmake flags i wonder why this is not working.
clang version 3.4 (tags/RELEASE_34/final)
Target: i386-portbld-freebsd9.1
Thread model: posix
Heres the function
#include <algorithm>
...
inline bool is_positive_number(const std::string & str)
{
if (str.empty())
return false;
return std::all_of(str.begin(), str.end(), ::isdigit);
}
Installer Log from pkg install clang34
Installing libexecinfo: 1.1_3
Installing llvm34: 3.4_1
Installing clang34: 3.4_2
Help appreciated i thought this function was implemented some ages ago but apparently im using it wrong or maybe i totally misunderstood something both is possible im quite new to clang.
Edit: Details of the process.
Selected GCC installation:
"/usr/local/llvm34/bin/clang" -cc1 -triple i386-portbld-freebsd9.1 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name main.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu i486 -target-linker-version 2.17.50 -v -v -g -coverage-file /home/source/release/server/game/CMakeFiles/game_r4708M_32.dir/src/main.cpp.o -resource-dir /usr/local/llvm34/bin/../lib/clang/3.4 -D "__SVN_VERSION__=\"\"" -I /home/source/release/server/game/../../extern/include/boost -I /home/source/release/server/game/../../extern/include -I /home/source/release/server/game/../libmysql/mysql-connector-c-6.1.5-src/output/freebsd/include -I /home/source/release/server/game/../liblua/include -I /home/source/release/server/game/../libdevil -internal-isystem /usr/include/c++/4.2 -internal-isystem /usr/include/c++/4.2/backward -Wno-invalid-source-encoding -W -Wno-invalid-source-encoding -W -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /home/source/release/server/game -ferror-limit 19 -fmessage-length 237 -mstackrealign -fobjc-runtime=gnustep -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o CMakeFiles/game_r4708M_32.dir/src/main.cpp.o -x c++ /home/source/release/server/game/src/main.cpp
clang -cc1 version 3.4 based upon LLVM 3.4 default target i386-portbld-freebsd9.1
ignoring duplicate directory "/usr/include/c++/4.2"
ignoring duplicate directory "/usr/include/c++/4.2"
ignoring duplicate directory "/usr/include/c++/4.2/backward"
#include "..." search starts here:
#include <...> search starts here:
/home/source/release/server/game/../../extern/include/boost
/home/source/release/server/game/../../extern/include
/home/source/release/server/game/../libmysql/mysql-connector-c-6.1.5-src/output/freebsd/include
/home/source/release/server/game/../liblua/include
/home/source/release/server/game/../libdevil
/usr/include/c++/4.2
/usr/include/c++/4.2/backward
/usr/local/llvm34/bin/../lib/clang/3.4/include
After switching to "-stdlib=libc++" as suggested by Steve Wills, I assume its selecting the right include path (v1) but its still not found or conflicted.
clang version 3.4 (tags/RELEASE_34/final)
Target: i386-portbld-freebsd9.1
Thread model: posix
Selected GCC installation:
"/usr/local/llvm34/bin/clang" -cc1 -triple i386-portbld-freebsd9.1 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name main.cpp -mrelocation-model static -mdisable-fp-elim -masm-verbose -mconstructor-aliases -target-cpu i486 -target-linker-version 2.17.50 -v -v -g -coverage-file /home/source/release/server/game/CMakeFiles/game_r4708M_32.dir/src/main.cpp.o -resource-dir /usr/local/llvm34/bin/../lib/clang/3.4 -D "__SVN_VERSION__=\"\"" -I /home/source/release/server/game/../../extern/include/boost -I /home/source/release/server/game/../../extern/include -I /home/source/release/server/game/../libmysql/mysql-connector-c-6.1.5-src/output/freebsd/include -I /home/source/release/server/game/../liblua/include -I /home/source/release/server/game/../libdevil -internal-isystem /usr/include/c++/v1 -Wno-invalid-source-encoding -W -Wno-invalid-source-encoding -W -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /home/source/release/server/game -ferror-limit 19 -fmessage-length 237 -mstackrealign -fobjc-runtime=gnustep -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -vectorize-slp -o CMakeFiles/game_r4708M_32.dir/src/main.cpp.o -x c++ /home/source/release/server/game/src/main.cpp
clang -cc1 version 3.4 based upon LLVM 3.4 default target i386-portbld-freebsd9.1
ignoring duplicate directory "/usr/include/c++/4.2"
#include "..." search starts here:
#include <...> search starts here:
/home/source/release/server/game/../../extern/include/boost
/home/source/release/server/game/../../extern/include
/home/source/release/server/game/../libmysql/mysql-connector-c-6.1.5-src/output/freebsd/include
/home/source/release/server/game/../liblua/include
/home/source/release/server/game/../libdevil
/usr/include/c++/v1
/usr/include/c++/4.2
/usr/include/c++/4.2/backward
/usr/local/llvm34/bin/../lib/clang/3.4/include
/usr/include
End of search list.
In file included from /home/source/release/server/game/src/main.cpp:1:
In file included from /home/source/release/server/game/src/stdafx.h:12:
/home/source/release/server/game/src/../../common/utils.h:120:14: error: no member named 'all_of' in namespace 'std'
This error is likely a result of a missing:
set( CMAKE_CXX_STANDARD 11 )
It would appear that there is something in your Cmake setup.
Or maybe that Cmake isn't very good at recognizing Clang?
The following minimal example;
#include <algorithm>
#include <string>
bool is_positive_number(const std::string & str);
int main(int argc, char *argv[]) {
is_positive_number("12");
}
bool is_positive_number(const std::string & str)
{
if (str.empty())
return false;
return std::all_of(str.begin(), str.end(), ::isdigit);
}
compiles without warnings using c++ or clang++ without any special directives;
c++ -Wall foo.cpp
For reference (reformatted for convenience):
c++ -### foo.cpp
FreeBSD clang version 3.4 (tags/RELEASE_34/final 197956) 20140216
Target: x86_64-unknown-freebsd10.0
Thread model: posix
"/usr/bin/c++" "-cc1" "-triple" "x86_64-unknown-freebsd10.0"
"-emit-obj" "-mrelax-all" "-disable-free" "-disable-llvm-verifier"
"-main-file-name" "foo.cpp" "-mrelocation-model" "static"
"-mdisable-fp-elim"
"-masm-verbose" "-mconstructor-aliases" "-munwind-tables"
"-target-cpu" "x86-64" "-resource-dir" "/usr/bin/../lib/clang/3.4"
"-internal-isystem" "/usr/include/c++/v1" "-fdeprecated-macro"
"-fdebug-compilation-dir" "/home/rsmith/tmp" "-ferror-limit" "19"
"-fmessage-length" "105" "-mstackrealign" "-fobjc-runtime=gnustep"
"-fcxx-exceptions" "-fexceptions" "-fdiagnostics-show-option"
"-fcolor-diagnostics" "-vectorize-slp" "-o" "/tmp/foo-206692.o"
"-x" "c++" "foo.cpp"
"/usr/bin/ld" "--eh-frame-hdr" "-dynamic-linker"
"/libexec /ld-elf.so.1" "--hash-style=both" "--enable-new-dtags"
"-o" "a.out" "/usr/lib/crt1.o" "/usr/lib/crti.o"
"/usr/lib/crtbegin.o" "-L/usr/lib" "/tmp/foo-206692.o"
"-lc++" "-lm" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
"-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
"/usr/lib/crtend.o" "/usr/lib/crtn.o"
Notice how this only uses "-internal-isystem" "/usr/include/c++/v1", while your invocation also uses /usr/include/c++/4.2" (which is from the old GCC c++ version 4.2).
to run all_of function you need c++11 complier
if you run the program in codeblocks then go to
setting --> compliers --> c++11 ISO c++ language standard [-std=c++11]
it will surely work
thank you good luck