I'm trying to compile bitcoin on my EC2 instance, and I've run into a problem I can't figure out. The build script stops on the following command
g++ -c -Wall -Wextra -Wformat -Wformat-security -Wno-unused-parameter -g -DMSG_NOSIGNAL=0 -DBOOST_SPIRIT_THREADSAFE -DUSE_UPNP=1 -DUSE_IPV6=1 -I/home/ec2-user/bitcoin/src/leveldb/include -I/home/ec2-user/bitcoin/src/leveldb/helpers -DHAVE_BUILD_INFO -I"/home/ec2-user/bitcoin/src" -I"/home/ec2-user/bitcoin/src/obj" -I"/usr/local/include" -I"/usr/include/openssl" -MMD -MF obj/alert.d -o obj/alert.o alert.cpp
by returning the following error(s)
In file included from /usr/include/sys/socket.h:40:0,
from compat.h:19,
from netbase.h:11,
from util.h:27,
from alert.h:13,
from alert.cpp:11:
/usr/include/bits/socket.h:231:5: error: expected identifier before numeric constant
/usr/include/bits/socket.h:231:5: error: expected ‘}’ before numeric constant
/usr/include/bits/socket.h:231:5: error: expected unqualified-id before numeric constant
In file included from compat.h:19:0,
from netbase.h:11,
from util.h:27,
from alert.h:13,
from alert.cpp:11:
/usr/include/sys/socket.h:254:1: error: expected declaration before ‘}’ token
I've tried compiling with the -std=c++0x option set, but it made no difference. That was the only thing I've been able to come up with.
I'd wager that some header file you have is #defineing a macro that interferes with socket.h. Are you able to compile a program that only includes <sys/socket.h>, with no other inclusions?
The next thing to check is to look at /usr/include/bits/socket.h and see what's on line 231 (where the first error occurs). If the code looks ok, then the next step is to see what the preprocessed source looks like. To get the preprocessed output, replace the -c option with -E on the command line, and change the -o obj/alert.o option to -o alert.ii to put the preprocessor output into the file alert.ii.
If you compare the content of alert.ii with /usr/include/bits/socket.h, you can see if it's getting compiled as expected or not. In particular, if there's a macro which defines something into something unexpected, you'll see code which is clearly wrong at the location the compiler is pointing out.
Related
I am having some issues with a makefile I am creating for a school project. I am compiling and assembling a C file and a SPARC assembly file (respectively) and linking them. I'm working in a Unix environment. Here is the makefile:
proj09.exe: proj09.driver.o proj09.support.o
<tab>gcc -Wall proj09.driver.o proj09.support.o -o proj09.exe
proj09.driver.o: proj09.driver.c /user/cse320/Projects/project09.support.h
<tab>gcc -Wall -c proj09.driver.c /user/cse320/Projects/project09.support.h
proj09.support.o: proj09.support.s
<tab>gcc -Wall proj09.support.s
When I try to make it, though, I get a reader error, specifically:
"Fatal error in reader: proj09.makefile, line 2: Unexpected end of line seen"
Now I know that usually this means that something is formatted incorrectly, but I have no idea what it could be in this case. Also, I am not 100% sure that this is the correct code for the makefile (specifically the assembling of my support.s file, and the linking of both files). I apologize if this is a repeat question, I looked through the archives beforehand and couldn't find anything of use. Any help would be greatly appreciated!
EDIT: I don't see why this would make a difference, but I am using gedit to actually write the code and then transferring the files into SSH for linking.
As Joachim told you, the lines should be indented by tab, not by spaces, so the second line should look like:
[TAB]gcc -Wall proj09.driver.o proj09.support.o -o proj09.exe[NEWLINE]
where [TAB] means TAB character.
Also there shouldn't be any spaces after the command. That's why I've put [NEWLINE] char.
Aside from the spaces and tabs, this doesn't generate an object file, shouldn't even compile (unless it has main()):
gcc -Wall proj09.support.s
You should use -c here too:
gcc -Wall -c proj09.support.s
Note: if you're working on Unix/Linux lose the .exe
I am writing a Rcpp code that include two library RcppArmadillo and trng4. However, when I include two header files (RcppArmadillo.h and trng/gamma_dist.hpp) it gives compilation error.
trng/special_functions.hpp:47:39: error: declaration of ‘float lgammaf(float) throw ()’ has a different exception specifier
extern "C" float lgammaf(float) throw();
include-fixed/math.h:476:14: error: from previous declaration ‘float lgammaf(float)’
extern float lgammaf(float);
Full compilation options are
-fopenmp -lgomp -DUSE_R -DNDEBUG -DDISABLE_SINGLE -DNTHROW -DDISABLE_FIO -I/usr/local/include -I"/Users/avi/Library/R/3.0/library/Rcpp/include" -I"/Users/avi/Library/R/3.0/library/RcppArmadillo/include" -fPIC -pipe -std=c++0x -Wall -pedantic -c
Seems like the lgammaf is declared in both header files. I tried using -E with g++ option but that give ld warning " .o, file was built for unsupported file format" and give error function in not available in .Call when I try it to after loading in R. What am I doing wrong?
Perhaps out of context I am using trng4 package to develop a thread gibbs sampler (in openmp) that sample from gamma distribution. I am currently running this MacOS. But eventual it will run in linux server.
It sounds like you do have a problem between Armadillo and trng4. Maybe you should try to, if possible, separate your interface so that you do not need to include from both in the same file.
Someone can correct me if I'm wrong, but I believe you prevent this issue by using #ifndef in each header file so that it's not defined a second time even if it's included a second time. But I guess these aren't your files are they...?
#ifndef __your_unique_header_name__
blah blah
#endif
I'm running into a strange issue when I try to compile the following simple C++11 code on my machine:
#include <boost/thread/thread.hpp>
It compiles fine with g++ foo.cpp -o foo but chokes on g++ -c -std=c++11 foo.cpp -o foo with the following error:
In file included from /usr/local/lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/functional:56:0,
from /usr/local/lib/gcc/x86_64-apple-darwin11.4.0/4.7.1/../../../../include/c++/4.7.1/memory:81,
from /usr/local/include/boost/config/no_tr1/memory.hpp:21,
from /usr/local/include/boost/smart_ptr/shared_ptr.hpp:27,
from /usr/local/include/boost/shared_ptr.hpp:17,
from /usr/local/include/boost/thread/pthread/thread_data.hpp:10,
from /usr/local/include/boost/thread/thread.hpp:17,
from foo.cpp:1:
./tuple:1:1: error: stray ‘\317’ in program
./tuple:1:1: error: stray ‘\372’ in program
./tuple:1:1: error: stray ‘\355’ in program
./tuple:1:1: error: stray ‘\376’ in program
... Additional lines omitted
I'm at a loss. Especially since I've been able to compile other programs against C++11 without any issue. Any ideas?
I'm running OS X v10.7.4 (Lion) and GCC 4.7.1.
That's because you have a file in your current directory named tuple that is included instead of the standard tuple header. Probably because of some -I. in the compilation line.
The strays characters in the error messages are simply the first bytes of the file not in the allowed character set, in octal.
I've been testing out clang-llvm to see if it is worth it to mention to my school's IT department to add it to the machines we students program on. For all of our assignments, we are required to compile using g++ -Wall -W -pedantic-errors *.cpp, so I just converted the command to clang++ -Wall -W -pedantic-errors. I got some output that I wasn't expecting:
Attempting to compile...
In file included from test_library.cpp:6:
In file included from ./test_library.h:64:
In file included from ./library.h:167:
./library.hpp:20:23: warning: unused variable 'e' [-Wunused-variable]
catch(Exception & e)
^
Whereas the GCC compiler does not give an error about unused variables in the catch block. Is there anything I can do so that Clang does not freak out about unused variables in try/catch blocks while keeping the command similar to the g++ one?
Clang-LLVM(v2.7) GNU GCC(v4.4.4) Fedora 13
I kinda agree with Mike, but for getting-off-the-ground's sake, try this:
clang++ -Wall -W -pedantic-errors -Wno-unused-variable
I haven't used llvm much but I think the point of the [-Wunused-variable] in the diagnostic is to tell you that you can shut that warning up with -Wno-unused-variable.
What's wrong with catching exception with "catch(Exception &)" if you are not using the variable? You compilers AND your code reviewers will be happier.
I include the amalgamation sqlite code in my iPhone project, and remove the reference to the iPhone sqlite framework.
My main target compile fine.
I have a second target for unit testing with the google framework. When compile I get:
error: syntax error before '#' token
I don't understand why. I have set both projects to sdk 2.
UPDATE: I include the link to the sqlite code & google. I must add that the target compile just fine for months before I added the sqlite code. I don't post sample code because I get 1263 errors - so I get error in all files -, but this is a sample traceback:
#class NSString, Protocol; <== ERROR HERE
Traceback:
cd /Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin"
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.0 -x c-header -arch i386 -fmessage-length=0 -pipe -std=c99 -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -D__IPHONE_OS_VERSION_MIN_REQUIRED=20000 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk -fvisibility=hidden -mmacosx-version-min=10.5 -gdwarf-2 -iquote /Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone/build/JhonSell.build/Debug-iphonesimulator/Testing.build/Testing-generated-files.hmap -I/Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone/build/JhonSell.build/Debug-iphonesimulator/Testing.build/Testing-own-target-headers.hmap -I/Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone/build/JhonSell.build/Debug-iphonesimulator/Testing.build/Testing-all-target-headers.hmap -iquote /Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone/build/JhonSell.build/Debug-iphonesimulator/Testing.build/Testing-project-headers.hmap -F/Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone/build/Debug-iphonesimulator -F/Volumes/CrashReporter-1.0-rc2/CrashReporter-iPhone -F/Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone -I/Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone/build/Debug-iphonesimulator/include -I/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk/usr/include/libxml2 "-I/Developer/RemObjects Software/Source" -I/Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone/build/JhonSell.build/Debug-iphonesimulator/Testing.build/DerivedSources/i386 -I/Users/trtrrtrtr/mamcx/projects/JhonSell/iPhone/build/JhonSell.build/Debug-iphonesimulator/Testing.build/DerivedSources -c /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h -o /var/folders/EA/EAmC8fuyElexZfnpnjdyr++++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/UIKit-dqqtnrciylhdtjbmyglpcezxchmz/UIKit.h.gch
In file included from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:12,
from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIAccelerometer.h:8,
from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h:9:
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.1.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObjCRuntime.h:120:
error: syntax error before '#' token
I finally figure out the problem.
I copy this from the iPhone target to the Testing target:
GCC_DYNAMIC_NO_PIC = NO
GCC_OPTIMIZATION_LEVEL = 0
GCC_PRECOMPILE_PREFIX_HEADER = YES
GCC_PREFIX_HEADER = JhonSell_Prefix.pch
GCC_PREPROCESSOR_DEFINITIONS = DEBUG
But why before I have not issues? I truly not understand.
With very little to go on, my guess would be including an Objective C header from a C/C++ implementation file, hence compiling the header in C/C++ instead of Objective C/Objective C++.
Looking at your updated information, you are actually compiling a header file, namely UIKit.h. The compiler has no idea what type of header file it is, so it defaults to C, which of course does not have #class and hence the syntax error.
So you will have to figure out why Xcode wants to compile UIKit.h in your second target.
Your gcc command line is compiling a .h file to a .gch file.
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.0
# ...
-x c-header -arch i386 -fmessage-length=0 -pipe -std=c99 -Wno-trigraphs # ...
# ...
# THE INPUT FILE:
/Developer/Platforms/iPhoneSimulator.platform/Developer/
SDKs/iPhoneSimulator2.2.1.sdk/System/Library/Framework/
UIKit.framework/Headers/UIKit.h
# THE OUTPUT FILE:
-o /var/folders/EA/EAmC8fuyElexZfnpnjdyr++++TI/
-Caches-/com.apple.Xcode.501/
SharedPrecompiledHeaders/UIKit-dqqtnrciylhdtjbmyglpcezxchmz/UIKit.h.gch
I.e. UIKit.h into UIKit.h.gch: translating a header file into a "precompiled" header that can be included faster because it is in a tokenized form.
Looks like the compiler doesn't know it's supposed to be precompiling a header; it is configured incorrectly somehow, and is just treating that as code to be actually compiled, and choking because the code is Objective C.