Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enabled -std=c++11 #6359

Closed
yaxinshen opened this issue Apr 21, 2018 · 37 comments
Closed

enabled -std=c++11 #6359

yaxinshen opened this issue Apr 21, 2018 · 37 comments

Comments

@yaxinshen
Copy link

yaxinshen commented Apr 21, 2018

PROTOC src/caffe/proto/caffe.proto
CXX .build_release/src/caffe/proto/caffe.pb.cc
In file included from /usr/include/c++/5/mutex:35:0,
from /usr/local/include/google/protobuf/stubs/mutex.h:33,
from /usr/local/include/google/protobuf/stubs/common.h:52,
from .build_release/src/caffe/proto/caffe.pb.h:9,
from .build_release/src/caffe/proto/caffe.pb.cc:4:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support
^
In file included from /usr/local/include/google/protobuf/stubs/common.h:52:0,
from .build_release/src/caffe/proto/caffe.pb.h:9,
from .build_release/src/caffe/proto/caffe.pb.cc:4:
/usr/local/include/google/protobuf/stubs/mutex.h:58:8: error: ‘mutex’ in namespace ‘std’ does not name a type
std::mutex mu_;
^
/usr/local/include/google/protobuf/stubs/mutex.h: In member function ‘void google::protobuf::internal::WrappedMutex::Lock()’:
/usr/local/include/google/protobuf/stubs/mutex.h:51:17: error: ‘mu_’ was not declared in this scope
void Lock() { mu_.lock(); }
^
/usr/local/include/google/protobuf/stubs/mutex.h: In member function ‘void google::protobuf::internal::WrappedMutex::Unlock()’:
/usr/local/include/google/protobuf/stubs/mutex.h:52:19: error: ‘mu_’ was not declared in this scope
void Unlock() { mu_.unlock(); }
^
/usr/local/include/google/protobuf/stubs/mutex.h: At global scope:
/usr/local/include/google/protobuf/stubs/mutex.h:61:7: error: expected nested-name-specifier before ‘Mutex’
using Mutex = WrappedMutex;
^
/usr/local/include/google/protobuf/stubs/mutex.h:66:28: error: expected ‘)’ before ‘*’ token
explicit MutexLock(Mutex *mu) : mu_(mu) { this->mu_->Lock(); }
^
/usr/local/include/google/protobuf/stubs/mutex.h:69:3: error: ‘Mutex’ does not name a type
Mutex const mu_;
^
/usr/local/include/google/protobuf/stubs/mutex.h: In destructor ‘google::protobuf::internal::MutexLock::~MutexLock()’:
/usr/local/include/google/protobuf/stubs/mutex.h:67:24: error: ‘class google::protobuf::internal::MutexLock’ has no member named ‘mu_’
~MutexLock() { this->mu_->Unlock(); }
^
/usr/local/include/google/protobuf/stubs/mutex.h: At global scope:
/usr/local/include/google/protobuf/stubs/mutex.h:80:33: error: expected ‘)’ before ‘
’ token
explicit MutexLockMaybe(Mutex *mu) :
^
In file included from /usr/local/include/google/protobuf/arena.h:48:0,
from .build_release/src/caffe/proto/caffe.pb.h:23,
from .build_release/src/caffe/proto/caffe.pb.cc:4:
/usr/include/c++/5/typeinfo:39:37: error: expected ‘}’ before end of line
/usr/include/c++/5/typeinfo:39:37: error: expected unqualified-id before end of line
/usr/include/c++/5/typeinfo:39:37: error: expected ‘}’ before end of line
/usr/include/c++/5/typeinfo:39:37: error: expected ‘}’ before end of line
/usr/include/c++/5/typeinfo:39:37: error: expected ‘}’ before end of line
/usr/include/c++/5/typeinfo:39:37: error: expected declaration before end of line
Makefile:588: recipe for target '.build_release/src/caffe/proto/caffe.pb.o' failed
make: *** [.build_release/src/caffe/proto/caffe.pb.o] Error 1

Tried solutions

add 'CXXFLAGs += -std=c++11' in Makefile didn't solve it

System configuration

  • Operating system: ubuntu 16.04
  • Compiler:
  • CUDA version (if applicable): 9.0
  • CUDNN version (if applicable): 7.0.4
  • Python version (if using pycaffe): tried both 2.7 and 3.6
@yeshengm
Copy link

I think this issue is related to protobuf, which uses C++ 11 features.

@EmpireofKings
Copy link

Hello my friend. what did you do to get this to work ? i have encountered the same issue, any help would be much appreciated.

@yeshengm
Copy link

yeshengm commented May 5, 2018

@EmpireofKings Generally there are two options: 1. use up-to-date protobuf, and add -std=c++11 to CXXFAGS in makefile, which could be a bit painful; 2. use protobuf 2.x, which is c++ 98 compatible.

@shallyxxxx
Copy link

I meet the same problem. Have you fixed it?@yaxinshen

@MINZHIJI
Copy link

@shallyxxxx
I solved this problem by modifying CMakeList.txt
Orginal

# ---[ Flags
if(UNIX OR APPLE)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall")
endif()if()

Modify

# ---[ Flags
if(UNIX OR APPLE)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -std=c++11")
endif()if()

@amitfishy
Copy link

amitfishy commented Jun 13, 2018

@manifoldQAQ
Thanks this worked for me. I also had to add it to the NVCCFLAGS in the makefile for it to build the NVCC portion successfully.
And also to LINKFLAGS for using make test.

CXXFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS) -std=c++11
NVCCFLAGS += -D_FORCE_INLINES -ccbin=$(CXX) -Xcompiler -fPIC $(COMMON_FLAGS) -std=c++11
LINKFLAGS += -pthread -fPIC $(COMMON_FLAGS) $(WARNINGS) -std=c++11

@ujsyehao
Copy link

@manifoldQAQ Good job!

@ujsyehao
Copy link

ujsyehao commented Jun 29, 2018

@amitfishy Hi, I follow your advice, and remove *.pb, then make it, it works well.
However, when I run ./build/tools/caffe train, it has the error:
155

How to solve the problem? I find some information about 'this program require a version of protobuf' # 5711, most solutions are to rollback protoc version to 2.6, but we need protoc version3.6, So how to make caffe support protobuf 3.6?

@amitfishy
Copy link

Firstly I followed the standard procedure for building caffe. Also I don't recall saying anything about the .pb files here.

I never came across this error specifically but came across similar things.
First take a look at the protoc version by:

protoc --version

You should see 2.6.1 which is your current protobuf version which you must have installed with apt-get.

You must be using cuda 9 which I believe needs v3.6, you can try installing the google protobuf by source. Following the install instructions will install in the default place which should be different from where your apt-get libraries are stored. Be careful if you try to remove the old libs or upgrade them, they can cause issues while booting.

Once you install by source, make sure it is being picked up correctly by checking with the version command or edit the order of the path variables as I've mentioned above in #3046 .

@ujsyehao
Copy link

ujsyehao commented Jun 29, 2018

@amitfishy I have installed protoc version3.6
156

@ujsyehao
Copy link

ujsyehao commented Jun 29, 2018

So I am confused,
When protocol version is 3.6, re-make caffe will cause the error:
"#error This file requires compiler and library support for the ISO C++ 2011 standard."
So I add -std=c++ 11 in makefile and it works well, this can explain caffe is using protoc 3.6.
when I run caffe, it says "this program requires version 3.6 of protocol, but the installed version is 2.6.1", why caffe report the error?

@amitfishy
Copy link

amitfishy commented Jun 29, 2018

Find the .so and .a libs (probably in /usr/local/lib) for your v3.6 and add them to LD_LIBRARY_PATH and LIBRARY_PATH env variables respectively. Make sure to add them in the beginning like:

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
echo $LD_LIBRARY_PATH //make sure /usr/local/lib is in start

Probably your makefile was pointing to those directories correctly and during runtime it's finding the other version.

@ujsyehao
Copy link

ujsyehao commented Jun 29, 2018

Thank you for your reply @amitfishy,
I have added them in LD_LIBRARY_PATH, but it doesn't work well, I guess your advice 'during runtime it's finding the other version' is right, how caffe find protoc during runtime?

@amitfishy
Copy link

amitfishy commented Jun 29, 2018

Go explore your file system. Find libprotobuf.a and libprotobuf.so (one set will be 9 and the other will be 15)
For v3.5
image

For v2.6
image

@amitfishy
Copy link

amitfishy commented Jun 29, 2018

Could you please try in the build folder:

ldd caffe | grep proto

And share the output?

@ujsyehao
Copy link

I don't understand.
158

@ujsyehao
Copy link

ujsyehao commented Jun 29, 2018

Follow your advice:
160
161
The caffe has two protobuf dll.

@amitfishy
Copy link

amitfishy commented Jun 29, 2018

It might be picking up the first one(v2.5) instead of the second (v3.6).

Try the following if you're still up for it:

make clean
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH
sudo ldconfig
make all
make test
make runtest

@ujsyehao
Copy link

Below is my another compiled caffe(protoc 2.6):

162

@amitfishy
Copy link

Try rebuilding it such that it gets linked with the right .so and .a libs. Don't forget the:

sudo ldconfig

After exporting the LD path.

@ujsyehao
Copy link

When I export LIBRARY_PATH, it has the error '/etc/profile: 30: bad assignment'.

@ujsyehao
Copy link

ujsyehao commented Jun 29, 2018

@amitfishy It works!
I am running 'make runtest'. I will post later.
hahaha
163
Thank you very much for your help @amitfishy !

@amitfishy
Copy link

Good to hear, the problem was the build was linked with the older libs, while the runtime libs were fine.

@ujsyehao
Copy link

ujsyehao commented Jun 29, 2018

In summary, the build was linked with older protoc version, I forget to make clean, and LIBRARY_PATH has no effect.
Now caffe can support protoc version 3.6!

@amitfishy
Copy link

Can you check what

ldd caffe | grep proto

gives you now?

@ujsyehao
Copy link

It gives the correct version.
164

@AliRaza21918
Copy link

AliRaza21918 commented Jul 11, 2018

CXX .build_release/src/caffe/proto/caffe.pb.cc
In file included from /usr/include/c++/5/mutex:35:0,
from /usr/local/include/google/protobuf/stubs/mutex.h:33,
from /usr/local/include/google/protobuf/stubs/common.h:52,
from .build_release/src/caffe/proto/caffe.pb.h:9,
from .build_release/src/caffe/proto/caffe.pb.cc:4:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support
^
In file included from /usr/local/include/google/protobuf/stubs/common.h:52:0,
from .build_release/src/caffe/proto/caffe.pb.h:9,
from .build_release/src/caffe/proto/caffe.pb.cc:4:
/usr/local/include/google/protobuf/stubs/mutex.h:70:8: error: ‘mutex’ in namespace ‘std’ does not name a type
std::mutex mu_;
^
/usr/local/include/google/protobuf/stubs/mutex.h: In member function ‘void google::protobuf::internal::WrappedMutex::Lock()’:
/usr/local/include/google/protobuf/stubs/mutex.h:63:43: error: ‘mu_’ was not declared in this scope
void Lock() GOOGLE_PROTOBUF_ACQUIRE() { mu_.lock(); }
^
/usr/local/include/google/protobuf/stubs/mutex.h: In member function ‘void google::protobuf::internal::WrappedMutex::Unlock()’:
/usr/local/include/google/protobuf/stubs/mutex.h:64:45: error: ‘mu_’ was not declared in this scope
void Unlock() GOOGLE_PROTOBUF_RELEASE() { mu_.unlock(); }
^
/usr/local/include/google/protobuf/stubs/mutex.h: At global scope:
/usr/local/include/google/protobuf/stubs/mutex.h:73:7: error: expected nested-name-specifier before ‘Mutex’
using Mutex = WrappedMutex;
^
/usr/local/include/google/protobuf/stubs/mutex.h:78:28: error: expected ‘)’ before ‘*’ token
explicit MutexLock(Mutex *mu) : mu_(mu) { this->mu_->Lock(); }
^
/usr/local/include/google/protobuf/stubs/mutex.h:81:3: error: ‘Mutex’ does not name a type
Mutex const mu_;
^
/usr/local/include/google/protobuf/stubs/mutex.h: In destructor ‘google::protobuf::internal::MutexLock::~MutexLock()’:
/usr/local/include/google/protobuf/stubs/mutex.h:79:24: error: ‘class google::protobuf::internal::MutexLock’ has no member named ‘mu_’
~MutexLock() { this->mu_->Unlock(); }
^
/usr/local/include/google/protobuf/stubs/mutex.h: At global scope:
/usr/local/include/google/protobuf/stubs/mutex.h:92:33: error: expected ‘)’ before ‘
’ token
explicit MutexLockMaybe(Mutex *mu) :
^
In file included from /usr/local/include/google/protobuf/arena.h:48:0,
from .build_release/src/caffe/proto/caffe.pb.h:23,
from .build_release/src/caffe/proto/caffe.pb.cc:4:
/usr/include/c++/5/typeinfo:39:37: error: expected ‘}’ before end of line
/usr/include/c++/5/typeinfo:39:37: error: expected unqualified-id before end of line
/usr/include/c++/5/typeinfo:39:37: error: expected ‘}’ before end of line
/usr/include/c++/5/typeinfo:39:37: error: expected ‘}’ before end of line
/usr/include/c++/5/typeinfo:39:37: error: expected ‘}’ before end of line
/usr/include/c++/5/typeinfo:39:37: error: expected declaration before end of line
Makefile:588: recipe for target '.build_release/src/caffe/proto/caffe.pb.o' failed
make: *** [.build_release/src/caffe/proto/caffe.pb.o] Error 1

anybody plz help me

libprotoc 3.6.0

@AliRaza21918
Copy link

i used both above stated solution
Makefile
CXXFLAGS ......
given by @amitfishy
and solution given by @MINZHIJI CMakeLists.txt

BUT both did not worked for me
PLZ HELP ANYBODY

@amitfishy
Copy link

Check the g++ specified in your makefile.

Try:

man g++      //or put whichever g++ binary is being picked up (/usr/bin/g++)

Scroll down and look whether -std flag has option for c++11. If it doesn't, try changing the g++ compiler version. I'm using:

g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.9) 5.4.0 20160609
Copyright (C) 2015 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.

@soulslicer
Copy link

soulslicer commented Dec 3, 2018

When will this be merged into Caffe??

@yeshengm
Copy link

yeshengm commented Dec 5, 2018

@soulslicer I guess Caffe is no longer actively maintained. You can either hack with Caffe source code or use Caffe2. If you don't want to use Caffe, then some dirty job has to be done to the Makefile in order to use Protobuf 3.x.

@soulslicer
Copy link

No you dont you just need to add that one word into the cmakelists.

@xiakj
Copy link

xiakj commented Dec 24, 2018

I also encountered this error, and the solutions didn't work for me. How to solve this problem?

make all -j8
NVCC src/caffe/layers/recurrent_layer.cu
NVCC src/caffe/layers/cudnn_lcn_layer.cu
NVCC src/caffe/layers/cudnn_lrn_layer.cu
NVCC src/caffe/layers/sigmoid_cross_entropy_loss_layer.cu
NVCC src/caffe/layers/batch_reindex_layer.cu
NVCC src/caffe/layers/mvn_layer.cu
NVCC src/caffe/layers/softmax_loss_layer.cu
NVCC src/caffe/layers/exp_layer.cu
In file included from /usr/include/c++/5/atomic:38:0,
from /usr/local/include/google/protobuf/io/coded_stream.h:113,
from .build_release/src/caffe/proto/caffe.pb.h:23,
from ./include/caffe/util/cudnn.hpp:8,
from ./include/caffe/util/device_alternate.hpp:40,
from ./include/caffe/common.hpp:19,
from ./include/caffe/blob.hpp:8,
from ./include/caffe/layers/cudnn_lrn_layer.hpp:6,
from src/caffe/layers/cudnn_lrn_layer.cu:4:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support \

@gongdalinux
Copy link

I also encountered this error, and the solutions didn't work for me. How to solve this problem?

make all -j8
NVCC src/caffe/layers/recurrent_layer.cu
NVCC src/caffe/layers/cudnn_lcn_layer.cu
NVCC src/caffe/layers/cudnn_lrn_layer.cu
NVCC src/caffe/layers/sigmoid_cross_entropy_loss_layer.cu
NVCC src/caffe/layers/batch_reindex_layer.cu
NVCC src/caffe/layers/mvn_layer.cu
NVCC src/caffe/layers/softmax_loss_layer.cu
NVCC src/caffe/layers/exp_layer.cu
In file included from /usr/include/c++/5/atomic:38:0,
from /usr/local/include/google/protobuf/io/coded_stream.h:113,
from .build_release/src/caffe/proto/caffe.pb.h:23,
from ./include/caffe/util/cudnn.hpp:8,
from ./include/caffe/util/device_alternate.hpp:40,
from ./include/caffe/common.hpp:19,
from ./include/caffe/blob.hpp:8,
from ./include/caffe/layers/cudnn_lrn_layer.hpp:6,
from src/caffe/layers/cudnn_lrn_layer.cu:4:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support \

I meet the same error(complie NVCC) with you. How do you solve it?

@vanpersie32
Copy link

@amitfishy 威武霸气

@chuyan0421
Copy link

chuyan0421 commented Jan 24, 2019

I use python=3.5 on anaconda .when protobuf =3.6 on anaconda, meeting the same problem. so change the protobuf =3.2 ,it will be OK!
"conda install protobuf = 3.2"

@k0suke-murakami
Copy link

I added below codes in Makefile since this solution did not work for some reason.
#6359 (comment)

NVCCFLAGS += -std=c++11
CXXFLAGS += -std=c++11
LINKFLAGS += -std=c++11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests