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.)
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
Why do I get error message when using mingw32-make on Win10 cmd. here is my Makefile code
all: compile link
compile:
g++ -I src/include -c main.cpp
link:
g++ main.o -o main -L src/lib -l sfml-graphics -l sfml-window -l sfml-system
here is the output on cmd
D:\Devs\C++\T2>mingw32-make
g++ -I src/include -c main.cpp
mingw32-make: Interrupt/Exception caught (code = 0xc0000005, addr = 0x00007FF89CC5F398)
but if run it manually and individually it compiles properly?
D:\Devs\C++\T2>g++ -I src/include -c main.cpp
D:\Devs\C++\T2>g++ main.o -o main -L src/lib -l sfml-graphics -l sfml-window -l sfml-system
No error, and when I run the the main.exe file, the updated code applies.
For further information, here the libraries version I'm using:
D:\Devs\C++\T2>g++ --version
g++ (GCC) 4.8.3
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.
D:\Devs\C++\T2>cmake --version
cmake version 3.20.3
CMake suite maintained and supported by Kitware (kitware.com/cmake).
Any tips? Thank you.
0xc0000005 is an Access Violation. It's coming from mingw32-make. I had hoped it might be a configuration error, or you might be able to fix it simply by reinstalling. That appears not to be the case.
Look here or here.
The answer in both cases was related to the Windows %PATH% string. Specifically:
https://superuser.com/questions/375029/make-interrupt-exception-caught
this problem is apparently caused when the PATH variable contains
parentheses (, ), as it does on Win Vista/7. Unfortunately, the
available GNU for Windows is hopelessly outdated.
My problem was fixed by forcing make use the correct shell: insert the
following line at the beginning of your makefile.
SHELL=C:/Windows/System32/cmd.exe
This question already has answers here:
Why does the order in which libraries are linked sometimes cause errors in GCC?
(9 answers)
Closed 6 years ago.
I am running ubuntu 16.04 with gcc.
My q.ccp file is
#include <my_messages.pb.h>
int main(int argc, char **argv)
{
google::protobuf::MyMessage* logged_msg_;
return 0;
}
command used for compilation:
g++ -m64 -Wl,-O1 -L/usr/lib/x86_64-linux-gnu /usr/local/lib/libprotobuf.a my_messages.pb.cc q.cpp -lpthread
protoc --version returns: 2.2.0
gcc --version
gcc (Ubuntu 4.8.5-4ubuntu2) 4.8.5
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.
compile error starts with
undefined reference to `google::protobuf::internal::ExtensionSet::Clear()
and gives undefined reference error for every function of protocol buffers.
Order of arguments to GCC matters a lot (libraries should go after object files and source files). You probably want
g++ -Wall -m64 -O1 -g -L/usr/lib/x86_64-linux-gnu -L/usr/local/lib/ \
my_messages.pb.cc q.cpp -lprotobuf -lpthread
(I would believe that -Wl,-O1 is wrong and useless, but I leave you to check that)
Take some time to read the GCC command options chapter of the documentation. You might want to (temporarily) use g++ -v instead of g++ in the command above to understand what is going on.
You probably should use GNU make for your build. See this example of Makefile for inspiration. Spend some time to read documentation of make.
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.