I've installed llvm 3.0 with llvm-gcc 4.6 on ubuntu 11.10. I'm trying to do the "example with llvm-gcc4" on http://llvm.org/docs/GettingStarted.html#tutorial4
But here's what I get:
buse#buseZenbook:~$ gcc --version
gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Copyright (C) 2011 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.
buse#buseZenbook:~$ llvm-gcc --version
gcc-4.6 (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
Copyright (C) 2011 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.
buse#buseZenbook:~$ llvm-gcc hello.c -o hello
Potential incompatible plugin version. GCC: 4.6. Expected: 4.6.1
Defines 'dragonegg_disable_version_check' as env variable to remove this warning
Please note that unexpected errors might occur.
buse#buseZenbook:~$ llvm-gcc -O3 -emit-llvm hello.c -c -o hello.bc
Potential incompatible plugin version. GCC: 4.6. Expected: 4.6.1
Defines 'dragonegg_disable_version_check' as env variable to remove this warning
Please note that unexpected errors might occur.
buse#buseZenbook:~$ ./hello
Hello World!
buse#buseZenbook:~$ lli hello.bc
lli: hello.bc:1:1: error: expected top-level entity
ELF>�##
^
And hello.c:
#include <stdio.h>
int main(){
printf("Hello World!\n");
return 0;
}
~
Any suggestions?
Related
I am trying to compile an altcoin QT wallet on a SolydK system. No matter what I try it always fails with
...
g++ -c -pipe -fstack-protector-all --param ssp-buffer-size=1 -D_FORTIFY_SOURCE=2 -O2 -D_REENTRANT -fdiagnostics-show-option -Wall -Wextra -Wno-ignored-qualifiers -Wformat -Wformat-security -Wno-unused-parameter -Wstack-protector -Wno-unused-variable -fpermissive -Wno-unused-local-typedefs -fPIE -DENABLE_WALLET -DBOOST_THREAD_USE_LIB -DBOOST_SPIRIT_THREADSAFE -DQT_DISABLE_DEPRECATED_BEFORE=0 -DBOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT -DUSE_DBUS -DHAVE_BUILD_INFO -DLINUX -DQT_NO_DEBUG -DQT_PRINTSUPPORT_LIB -DQT_WIDGETS_LIB -DQT_DBUS_LIB -DQT_NETWORK_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/lib/i386-linux-gnu/qt5/mkspecs/linux-g++ -Isrc -Isrc/json -Isrc/qt -Isrc/qt/plugins/mrichtexteditor -Isrc/leveldb/include -Isrc/leveldb/helpers -Isrc/secp256k1/include -Idb4/include -isystem /usr/include/i386-linux-gnu/qt5 -isystem /usr/include/i386-linux-gnu/qt5/QtPrintSupport -isystem /usr/include/i386-linux-gnu/qt5/QtWidgets -isystem /usr/include/i386-linux-gnu/qt5/QtDBus -isystem /usr/include/i386-linux-gnu/qt5/QtNetwork -isystem /usr/include/i386-linux-gnu/qt5/QtGui -isystem /usr/include/i386-linux-gnu/qt5/QtCore -Ibuild -Ibuild -o build/bitcoin.o src/qt/bitcoin.cpp
In file included from src/wallet.h:8:0,
from src/qt/walletmodel.h:12,
from src/qt/bitcoin.cpp:9:
src/walletdb.h:96:1: error: expected class-name before ‘{’ token
{
^
In file included from src/wallet.h:8:0,
from src/qt/walletmodel.h:12,
from src/qt/bitcoin.cpp:9:
src/walletdb.h:153:25: error: ‘CDBEnv’ has not been declared
static bool Recover(CDBEnv& dbenv, std::string filename, bool fOnlyKeys);
^
src/walletdb.h:154:25: error: ‘CDBEnv’ has not been declared
static bool Recover(CDBEnv& dbenv, std::string filename);
^
In file included from src/wallet.h:8:0,
from src/qt/walletmodel.h:12,
from src/qt/bitcoin.cpp:9:
src/walletdb.h: In constructor ‘CWalletDB::CWalletDB(const string&, const char*)’:
src/walletdb.h:98:77: error: class ‘CWalletDB’ does not have any field named ‘CDB’
CWalletDB(const std::string& strFilename, const char* pszMode = "r+") : CDB(strFilename, pszMode)
^
make: *** [build/bitcoin.o] Error 1
I gather it's a class inheritance error. But the exact same source (pulled from github) compiles fine on Mint 17.3 (Ubuntu 14.04 LTS) and Xubuntu 16.04 LTS systems. There are 752 SO questions regarding "error: expected class-name before ‘{’ token" but none are for bitcoin.cpp or walletdb.h.
I don't believe it's a Qt problem; I get the same error whether using Qt4 or Qt5 on the SolydK system. I also get the same error if trying to build the daemon instead of the GUI wallet (in which case the error comes when compiling init.cpp). The offending section of the named walletdb.h is
...
94 /** Access to the wallet database (wallet.dat) */
95 class CWalletDB : public CDB
96 {
97 public:
98 CWalletDB(const std::string& strFilename, const char* pszMode = "r+") : CDB(strFilename, pszMode)
99 {
100 }
101 private:
102 CWalletDB(const CWalletDB&);
103 void operator=(const CWalletDB&);
104 public:
105 bool WriteName(const std::string& strAddress, const std::string& strName );
106
107 bool EraseName(const std::string& strAddress);
...
I wondered if it's something to do with different default options for the different compiler versions. On Mint I have
mark gbx $ g++ --version
g++ (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4
Copyright (C) 2013 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.
On Xubuntu it is
mark#xubuntu:~/src/EarnzCoin$ g++ --version
g++ (Ubuntu 5.4.0-6ubuntu1~16.04.5) 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.
and on the failing SolydK it is
mark#traveller ~/src/EarnzCoin $ g++ --version
g++ (Debian 4.9.2-10) 4.9.2
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.
But I can't see any obvious significant differences (eg: value for --std) using g++ --dumpspecs nor in the qmake generated Makefiles.
About half a dozen other altcoins compile fine on the SolydK system.
This isn't my code, I haven't changed it at all, just trying to compile it. There are no Google hits for this inheritance error with bitcoin.cpp or walletdb.h
I'm not a C++ programmer, don't want to be. No-one else has reported this error anywhere I can find it so it's probably something related to my SolydK system, but I don't know what.
Any suggestions for other things to check/try?
Seems like base class CDB is missing (header not available or not included). Check if it's an external package, and install the development files if necessary. If not there may be a #define somewhere that makes the class unavailable on that specific system, e. g. because prerequisites are missing.
I am having an old problem on a new compiler. While trying to print the current time using std::chrono I receive the following error:
src/main.cpp:51:30: error: ‘put_time’ is not a member of ‘std’
std::cout << std::put_time(std::localtime(&time), "%c") << "\n\n";
^~~
The offending snippet is nothing special:
#include <chrono>
...
auto time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
std::cout << std::put_time(std::localtime(&time), "%c") << "\n\n";
This looks an awful lot like the errors being returned in the GCC 4.x series, as referenced all over the place:
std::put_time implementation status in GCC?
Why does std::put_time not compile using multiple compilers?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54354
The only problem with this theory is that my GCC is modern:
$ g++ --version
g++ (GCC) 6.3.1 20161221 (Red Hat 6.3.1-1)
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 also checked that my application is linking against the appropriate libraries:
$ ldd build/myapp
...
libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007fde97e7b000)
libc.so.6 => /lib64/libc.so.6 (0x00007fde97595000)
Finally, there is nothing exotic going on in my compile flags:
g++ -g -Wall -Werror -std=c++11 -Wno-sign-compare src/main.cpp -c -o obj/main.o
Everything I can think to check indicates that this should be working. So, in short, what gives?
The problem is that you included the wrong header. std::put_time is declared in <iomanip>, not <chrono>.
Also, it is not complaining about any of the other time operations such as std::localtime and to_time_t.
std::localtime is declared in <ctime>.
This is not a duplicate question, because the solutions presented are not working on my compiler. I am trying to compile and run the following example from this question.
#include <thread>
#include <iostream>
int main(int, char **){
std::thread tt([](){ std::cout<<"Thread!"<<std::endl; });
tt.join();
}
I have attempted to use the solutions presented in both that original question as well as the accepted answer to this duplicate. However, although I tried all the combinations listed, and in particular tried
g++ main.cpp -o main.out -pthread -std=c++11
When I run the resulting executable, I still get
terminate called after throwing an instance of 'std::system_error'
what(): Enable multithreading to use std::thread: Operation not permitted
Aborted (core dumped)
Here is the output of g++ --version.
g++ (Ubuntu/Linaro 4.8.1-10ubuntu9) 4.8.1
Copyright (C) 2013 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.
Is there a different ordering or set of commands I need to use for g++ 4.8.1?
this was answered here
g++ -Wl,--no-as-needed -std=c++11 -pthread main.cpp -o main.out
I'm trying to run a program which uses __builtin_popcountll function.
When I compile the code using makefile which compiles source files with command/flags as shown below:
g++ -c -Wall `pkg-config opencv --cflags` -I./include -O3 -fopenmp -msse4.2 src/Utils.cpp -o src/Utils.o
It compiles without any error / warning. However, when I try to link the object (.o) files to build an executable, I get undefined symbols error.
Here is the command:
g++ src/BoostDesc.o src/Utils.o src/main.o `pkg-config opencv --libs` -lgomp -o main
and this is the complete error:
Undefined symbols for architecture x86_64:
"___builtin_popcountll", referenced from:
__ZN9boostDesc5Utils12matchHammingERKN2cv3MatERKSt6vectorIS2_SaIS2_EERS5_IS5_INS1_6DMatchESaISA_EESaISC_EE.omp_fn.0 in Utils.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
make: *** [main] Error 1
I looked up the man page for gcc on Apple's website here, and it suggests that the flag works and I'm assuming it should work for g++ as well. Can someone confirm or refute the possibility of using this builtin function? Thnx!
g++ --version returns this:
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
This optimization is specified either by doing: -mpopcnt or -march=corei7 to the compilation.
Take one sample:
% cat popcountl.c
int main(int argc , char** argv)
{
volatile long long x = 0xf0f0f0f0f0f0f0f0;
return __builtin_popcountll(x);
}
Turns out not to be supported in that version of g++:
~/D/e/popcountl [1]> /Applications/Xcode\ 4.6.3.app/Contents/Developer/usr/bin/g++ -mpopcnt -c popcountl.c
cc1plus: error: unrecognized command line option "-mpopcnt"
~/D/e/popcountl [1]> /Applications/Xcode\ 4.6.3.app/Contents/Developer/usr/bin/g++ -march=corei7 -c popcountl.c
popcountl.c:1: error: bad value (corei7) for -march= switch
popcountl.c:1: error: bad value (corei7) for -mtune= switch
~/D/e/popcountl> /Applications/Xcode\ 4.6.3.app/Contents/Developer/usr/bin/g++ --version
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Copyright (C) 2007 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.
Works with Xcode5 g++ though.
% g++ --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 5.0 (clang-500.2.75) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
g++ -mpopcnt -c popcountl.cpp
dhcp-3-127:~% otool -tV popcountl.o
popcountl.o:
:
0000000000000024 popcntq %rax, %rax
It looks like the flags for this optimization are not present in the 4.6 version of the XCode supplied compilers, but are present in the 5.0 version of the XCode compilers.
Bear in mind that you're actually running the llvm compiler with a g++ front-end, so it's not actually running official g++; this is probably the underlying reason for it not working properly in this case.
I'm trying to compile using g++ and either the -std=c++11 or c++0x flags.
However, I get this error
cc1plus: error: unrecognized command line option "-std=c++11"
g++ --version
g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-54)
Copyright (C) 2006 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.
Seeing from your G++ version, you need to update it badly. C++11 has only been available since G++ 4.3. The most recent version is 4.7.
In versions pre-G++ 4.7, you'll have to use -std=c++0x, for more recent versions you can use -std=c++11.
Quoting from the gcc website:
C++11 features are available as part of the "mainline" GCC compiler in the trunk of GCC's Subversion repository and in GCC 4.3 and later. To enable C++0x support, add the command-line parameter -std=c++0x to your g++ command line. Or, to enable GNU extensions in addition to C++0x extensions, add -std=gnu++0x to your g++ command line. GCC 4.7 and later support -std=c++11 and -std=gnu++11 as well.
So probably you use a version of g++ which doesn't support -std=c++11. Try -std=c++0x instead.
Availability of C++11 features is for versions >= 4.3 only.
you should try this
g++-4.4 -std=c++0x or g++-4.7 -std=c++0x
I also got same error, compiling with -D flag fixed it, Try this:
g++ -Dstd=c++11