I am trying to convert some gpl code(not mine!) from C++ to C so I can use it in a c-only project. I read about llvm and got excited but I am running into a linker error that I have no idea how to fix:
the error is:
Intrinsic prototype has incorrect number of arguments!
void (i8*, i8*, i64, i32, i1)* #llvm.memmove.p0i8.p0i8.i64
Broken module found, compilation aborted!
Stack dump:
0. Running pass 'Function Pass Manager' on module 'ld-temp.o'.
1. Running pass 'Module Verifier' on function '#_ZNSt15__copy_backwardILb1ESt26random_access_iterator_tagE8__copy_bIxEEPT_PKS3_S6_S4_'
Anyone ever see this before? Any idea what could cause it?
Here is the commands I used to get this far:
dhcp-100-140:src joeltucci$ llvm-g++ msb.C -c -emit-llvm
dhcp-100-140:src joeltucci$ llvm-g++ rabincmd.C -c -emit-llvm
In file included from rabincmd.C:27:
rabinpoly.h: In member function ‘u_int64_t rabinpoly::append8(u_int64_t, u_char) const’:
rabinpoly.h:56: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘long int’
rabincmd.C: In function ‘void printChunkContents(u_int64_t, const unsigned char*, int)’:
rabincmd.C:91: warning: too few arguments for format
rabincmd.C: In member function ‘virtual void ExtractChunkProcessor::internalCompleteChunk(u_int64_t, u_int64_t)’:
rabincmd.C:547: warning: deprecated conversion from string constant to ‘char*’
rabincmd.C:551: warning: deprecated conversion from string constant to ‘char*’
dhcp-100-140:src joeltucci$ llvm -ld m
mkrabincmd.sh msb.C msb.o
mkverboseRabin.sh msb.h
dhcp-100-140:src joeltucci$ llvm -ld *.o -o program
-bash: llvm: command not found
dhcp-100-140:src joeltucci$ llvm-ld *.o -o program
-bash: llvm-ld: command not found
dhcp-100-140:src joeltucci$ llvm-
llvm-cpp-4.2 llvm-g++ llvm-g++-4.2 llvm-gcc llvm-gcc-4.2
dhcp-100-140:src joeltucci$ llvm-g++ *.o -o program
collect2: ld terminated with signal 6 [Abort trap]
Intrinsic prototype has incorrect number of arguments!
void (i8*, i8*, i64, i32, i1)* #llvm.memmove.p0i8.p0i8.i64
Broken module found, compilation aborted!
Stack dump:
0. Running pass 'Function Pass Manager' on module 'ld-temp.o'.
1. Running pass 'Module Verifier' on function '#_ZNSt15__copy_backwardILb1ESt26random_access_iterator_tagE8__copy_bIxEEPT_PKS3_S6_S4_'
dhcp-100-140:src joeltucci$ llvm-gcc --version
i686-apple-darwin10-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2332.3)
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.
dhcp-100-140:src joeltucci$
dhcp-100-140:src joeltucci$
dhcp-100-140:src joeltucci$
dhcp-100-140:src joeltucci$ llvm-g++ *.o -o program
llvm-g++ llvm-g++-4.2
dhcp-100-140:src joeltucci$ llvm-gcc-4.2 --version
i686-apple-darwin10-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2332.3)
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.
Well your problem is probably a line up
llvm -ld *.o -o program -bash: llvm: command not found dhcp-100-140:src
The error you list is most likely related to llvm -ld not being found, therefore you're missing some needed files in the next command..... did you mean llvm-ld instead?
Related
I am working with some code that requires g++12 I could not find a better way to install g++ 12 on Ubuntu 20.4.4 so I installed it using homebrew. When I run g++-12 --version I get
g++-12 (Homebrew GCC 12.2.0) 12.2.0 Copyright (C) 2022 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.
When I try to compile any program using g++-12 I get the error
/usr/bin/ld: cannot find -lm collect2: error: ld returned 1 exit
status
I have tried adding a -L and -I flags that point to lib and include folders of the homebrew install of g++ 12 but this does not seem to help.
g++-12 -std=gnu++20 main.cpp track.cpp -o track
g++-12 -o hello HelloWorld.cpp
I followed the tutorial to connect to DolphinDB server with C++ and encounted this error message when compiling main.cpp:
$ g++ main.cpp -std=c++11 -DLINUX -DLOGGING_LEVEL_2 -O2 -I../include -lDolphinDBAPI -lssl -lpthread -luuid -L../bin -Wl,-rpath ../bin/ -o main
/usr/bin/ld: cannot find -lssl
collect2: error: ld returned 1 exit status
Note that my g++ version is above v6.2:
$ g++ --version
g++ (Ubuntu 7.4.0-1ubuntu1~18.04) 7.4.0
Copyright (C) 2017 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.
How to solve this error?
If you want to link against OpenSSL, you need to install the development package for OpenSSL, like this:
apt install libssl-dev
It may also be possible to drop the -lssl from the linker command line. (If there was a project dependency on OpenSSL, the build would not have gotten this far because the OpenSSL header files are missing, too.)
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.
Context
I'm trying to compile the package "root_numpy" which is a link between the scientific analysis software "root" and the python package "numpy". It's used as part of the root wrapper "rootpy". I get a g++ error when the following line is executed:
g++ -bundle -undefined dynamic_lookup -g -arch x86_64 -headerpad_max_install_names
-arch x86_64 build/temp.macosx-10.6-x86_64-2.7/root_numpy/src/_librootnumpy.o
-o build/lib.macosx-10.6-x86_64-2.7/root_numpy/_librootnumpy.so
-L/Users/bwells/bin/root/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d
-lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread
-lpthread -Wl,-rpath,/Users/bwells/bin/root/lib -stdlib=libc++ -lm -ldl
-lTreePlayer
g++: error: unrecognized command line option '-stdlib=libc++'
The same problem occurs when I compile a "hello world" program with the flag:
dhcp-130-112:helloworld bwells$ g++ -stdlib=libc++ helloworld.cpp
g++: error: unrecognized command line option '-stdlib=libc++'
Without that flag, it compiles fine:
dhcp-130-112:helloworld bwells$ g++ helloworld.cpp
dhcp-130-112:helloworld bwells$ ls
a.out helloworld.cpp
My compiler version is:
dhcp-130-112:helloworld bwells$ g++ --version
g++ (MacPorts gcc48 4.8.2_2) 4.8.2
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.
AKA the result of running sudo port install gcc48. My Mac OS version is 10.9.3. The code file "helloworld.cpp" is as you'd expect
dhcp-130-112:helloworld bwells$ cat helloworld.cpp
#include <iostream>
int main(void)
{
std::cout << "Hello world!" << std::endl;
return 0;
}
dhcp-130-112:helloworld bwells$
Question: From everything I can gather on the internet, the "-stdlib=..." flag is a standard part of g++. Why do I get a g++ error when including it? How can I fix this?
Note:
While manually executing the setup.py line without the problem flag works, and allows the full package to compile, I experience linking errors when I try to import the resulting package into python. I'm concerned that the g++ problem here is a symptom of a larger issue, which is why I'm trying to solve it directly.
-stdlib=libc++ is a Clang (not GCC) option and tells clang to use LLVM libc++ standard library (which is what Clang uses) rather than GNU libstdc++ (which is what GCC uses).
Since you got linking errors, it seems likely that other packages you are using were compiled with clang and libc++, which is not ABI compatible with GCC's libstdc++ (except for some low-level stuff). So you'll need to compile the package with clang and libc++ as well. Apple's Xcode comes with clang (which is probably what you'd want to use for this), and MacPorts also supplies a number of clang distributions.
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.