When linking my hdf5 code I get the following error. Any ideas what I have done wrong.
The command I am using:
g++ -std=c++11 -m64 -DOPENFOAM_PLUS=1712 -Dlinux64 -DWM_ARCH_OPTION=64 -DWM_DP -DWM_LABEL_SIZE=32 -Wall -Wextra -Wold-style-cast -Wnon-virtual-dtor -Wno-unused-parameter -Wno-invalid-offsetof -Wno-attributes -O3 -DNoRepository -ftemplate-depth-100 -I/opt/software/OpenFOAM/OpenFOAM-v1712/src/finiteVolume/lnInclude -I/opt/software/OpenFOAM/OpenFOAM-v1712/src/sampling/lnInclude -I/opt/software/OpenFOAM/OpenFOAM-v1712/src/meshTools/lnInclude -IlnInclude -I. -I/opt/software/OpenFOAM/OpenFOAM-v1712/src/OpenFOAM/lnInclude -I/opt/software/OpenFOAM/OpenFOAM-v1712/src/OSspecific/POSIX/lnInclude -fPIC -Xlinker --add-needed -Xlinker --no-as-needed Make/linux64GccDPInt32Opt/3DIBicoFoam_2.o -L/opt/software/OpenFOAM/OpenFOAM-v1712/platforms/linux64GccDPInt32Opt/lib \
-lfiniteVolume -lsampling -L/local/hulfeldl/hdf5/lib/libhdf5_hl_cpp.a -L/local/hulfeldl/hdf5/lib/libhdf5_cpp.a -L/local/hulfeldl/hdf5/lib/libhdf5_hl.a -L/local/hulfeldl/hdf5/lib/libhdf5.a -lhdf5_hl_cpp -lhdf5_cpp -lhdf5_hl -lhdf5 -lsz -lz -ldl -lm -lOpenFOAM -ldl \
-lm -o /local/hulfeldl/OpenFOAM/hulfeldl-v1712/applications/bin/linux64GccDPInt32Opt/3DIBicoFoam_2
Error:
Make/linux64GccDPInt32Opt/3DIBicoFoam_2.o: In function `main':
3DIBicoFoam_2.C:(.text.startup+0x107b): undefined reference to
`H5::H5Location::openDataSet(std::string const&) const'
3DIBicoFoam_2.C:(.text.startup+0x17de): undefined reference to
`H5::H5Location::openDataSet(std::string const&) const'
3DIBicoFoam_2.C:(.text.startup+0x189e): undefined reference to
`H5::H5Location::openDataSet(std::string const&) const'
3DIBicoFoam_2.C:(.text.startup+0x1919): undefined reference to
`H5::H5Location::openDataSet(std::string const&) const'
3DIBicoFoam_2.C:(.text.startup+0x19d0): undefined reference to
`H5::H5Location::openDataSet(std::string const&) const'
Please remove all -L/...a to start with. Add one single -L/local/hulfeldl/hdf5/lib leave all -lhdf... in the command. And retry.
For runtime please run the following before you run your program.
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/local/hulfeldl/hdf5/lib
Related
/usr/bin/cmake -E cmake_link_script CMakeFiles/YikeSim.dir/link.txt --verbose=1
/data/mpich/bin/mpic++ -Wl,--rpath=./shared_lib/linux -std=c++17 -g -O3 -mavx -fopenmp -Wall -D CMAKE_COMPILE -L /usr/lib64 CMakeFiles/YikeSim.dir/src/main/main.cpp.o CMakeFiles/YikeSim.dir/src/yikesim/extern/NanoLog.cpp.o -o out/build/mingw-build/YikeSim -L/data/project/YikeFDTDBook/YikeSim/shared_lib/linux -L/data/project/YikeFDTDBook/YikeSim/static_lib/linux -rdynamic -lboost_timer -lboost_chrono -lboost_thread -lpython3.8 -lc -lopenblas -lgmsh -lpthread -Wl,-rpath,/data/project/YikeFDTDBook/YikeSim/shared_lib/linux:/data/project/YikeFDTDBook/YikeSim/static_lib/linux
/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: CMakeFiles/YikeSim.dir/src/main/main.cpp.o: in function `std::string::_M_check(unsigned long, char const*) const':
/opt/rh/devtoolset-10/root/usr/include/c++/10/bits/basic_string.h:3392: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'
/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/ld: /opt/rh/devtoolset-10/root/usr/include/c++/10/bits/basic_string.h:3392: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)'
This is the message I get when I compile the program with an error. I have searched the web for a solution and most of the answers are about the GCC version. But I have tried devtoolset-8, devtoolset-9, devtoolset-10 and still get the same error. I hope there is an effective solution to this problem, thank you very much.
I'm using compile downloaded source code and try to make my c++ project but these error appear.
user1#ubuntu:~$ make
g++ -std=c++0x -g -Wall -Werror -L/home/user1/project0/libcurl/lib/libcurl.a -I/home/user1/proj/libcurl/include -c my-curl.cpp -o curl.o
g++ -std=c++0x -g -Wall -Werror -L/home/user1/project0/libcurl/lib/libcurl.a -I/home/user1/proj/libcurl/include -c main.cpp -o main.o
g++ -std=c++0x -g -Wall -Werror -L/home/user1/project0/libcurl/lib/libcurl.a -I/home/user1/proj/libcurl/include -o my-curl-app my-curl.o main.o
my-curl.o: In function `CCurlDownloader::start_download()':
~/my-curl.cpp:22: undefined reference to `curl_easy_init'
~/my-curl.cpp:27: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:28: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:29: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:30: undefined reference to `curl_easy_perform'
~/my-curl.cpp:53: undefined reference to `curl_easy_cleanup'
collect2: ld returned 1 exit status
make: *** [my-curl-app] Error 1
and i'm changed -L option to specified directory and add -lcurl for specified lib and result is.
user1#ubuntu:~/project0/my-curl$ make
g++ -std=c++0x -g -Wall -Werror -L/home/user1/practics/libcurl/lib -lcurl -I/home/user1/practics/libcurl/include -c my-curl.cpp -o my-curl.o
g++ -std=c++0x -g -Wall -Werror -L/home/user1/practics/libcurl/lib -lcurl -I/home/user1/practics/libcurl/include -c main.cpp -o main.o
g++ -std=c++0x -g -Wall -Werror -L/home/user1/practics/libcurl/lib -lcurl -I/home/user1/practics/libcurl/include -o my-curl-cpp my-curl.o main.o
my-curl.o: In function `CCurlDownloader::start_download()':
~/my-curl.cpp:22: undefined reference to `curl_easy_init'
~/my-curl.cpp:27: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:28: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:29: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:30: undefined reference to `curl_easy_perform'
~/my-curl.cpp:53: undefined reference to `curl_easy_cleanup'
collect2: ld returned 1 exit status
make: *** [bb-cppurl] Error 1
I and try curl-config to link libs but result still be the same.
user1#atom-linux-server:~/my-curl$ make
g++ -std=c++0x -g -Wall -Werror `/home/user1/project0/libcurl/bin/curl-config --libs` `/home/user1/project0/libcurl/bin/curl-config --cflags` -c my-curl.cpp -o my-curl.o
g++ -std=c++0x -g -Wall -Werror `/home/user1/project0/libcurl/bin/curl-config --libs` `/home/user1/project0/libcurl/bin/curl-config --cflags` -c main.cpp -o main.o
g++ -std=c++0x -g -Wall -Werror `/home/user1/project0/libcurl/bin/curl-config --libs` `/home/user1/project0/libcurl/bin/curl-config --cflags` -o my-curl-app my-curl.o main.o
my-curl.o: In function `CCurlDownloader::start_download()':
~/my-curl.cpp:22: undefined reference to `curl_easy_init'
~/my-curl.cpp:27: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:28: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:29: undefined reference to `curl_easy_setopt'
~/my-curl.cpp:30: undefined reference to `curl_easy_perform'
~/my-curl.cpp:53: undefined reference to `curl_easy_cleanup'
collect2: ld returned 1 exit status
make: *** [bb-cppurl] Error 1
You're using the build tools wrong.
1 - the -L option should specify a directory
2 - there's no -l (lowercase L) option to specify which lib to link with (perhaps from the directory -L identifies)
I move
-L/home/user1/practics/libcurl/lib -lcurl
to the tail of command
g++ -std=c++0x -g -Wall -Werror -I/home/user1/practics/libcurl/include -o my-curl-cpp my-curl.o main.o -L/home/user1/practics/libcurl/lib -lcurl
and it works.
I am running Linux Mint 14.1 64-bit
I have installed the following libs:
mesa-common-dev,
freeglut3-dev,
libglew-dev
through the apt-get tool.
Here are my includes, located in my Main.h file:
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <GL/glew.h>
#include <GL/glut.h>
#include <time.h>
I checked that the libs installed correctly, they seem to be located in /usr/lib/x86_64-linux-gnu
and the headers in /usr/include/GL
I proceed to compile my Main.C file with the following flags:
g++ -Wall -Wextra -Weffc++ -Winit-self -Wmissing-include-dirs -Wswitch-default -switch-enum -Wunused-parameter -Wstrict-overflow=5 -Wfloat-equal -Wshadow -Wc++0x-compat -Wconversion -Wsign-conversion -Wmissing-declarations -Wstrict-null-sentinel -Woverloaded-virtual -Wsign-promo -Werror -pedantic -Wcast-qual -fno-pretty-templates -fmessage-length=80 -fdiagnostics-show-option -g -std=c++0x -pipe -frepo -c Main.C -o Main.o
Main.o is generated without any issues, then I try to create the binary:
g++ -I/usr/include -L/usr/lib/x86_64-linux-gnu -lGL -lglut -lGLU -lGLEW -lX11 -lm -lrt -lpng Main.o -o main
And receive the following errors:
Main.o: In function `init()':
/path/to/Main.C:12: undefined reference to `glClearColor'
Main.o: In function `initGLUT(int, char**)':
/path/to/Main.C: undefined reference to `glutInit'
/path/to/Main.C:21: undefined reference to `glutInitDisplayMode'
/path/to/Main.C:24: undefined reference to `glutInitWindowSize'
/path/to/Main.C:25: undefined reference to `glutCreateWindow'
/path/to/Main.C:28: undefined reference to `glutDisplayFunc'
/path/to/Main.C:31: undefined reference to `glutKeyboardFunc'
/path/to/Main.C:34: undefined reference to `glutMouseFunc'
/path/to/Main.C:37: undefined reference to `glutReshapeFunc'
/path/to/Main.C:40: undefined reference to `glutIdleFunc'
Main.o: In function `printFPS()':
/path/to/Main.C:96: undefined reference to `glutGet'
Main.o: In function `reshape(int, int)':
/path/to/Main.C:123: undefined reference to `glutPostRedisplay'
Main.o: In function `getTime()':
/path/to/Main.C:129: undefined reference to `glutGet'
Main.o: In function `idle()':
/path/to/Main.C:141: undefined reference to `glutPostRedisplay'
Main.o: In function `display()':
/path/to/Main.C:148: undefined reference to `glClearColor'
/path/to/Main.C:149: undefined reference to `glClear'
/path/to/Main.C:150: undefined reference to `glFlush'
/path/to/Main.C:151: undefined reference to `glutSwapBuffers'
Main.o: In function `main':
/path/to/Main.C:164: undefined reference to `glutMainLoop'
The program compiles and links on another Linux system though.
what could I be missing?
You have to pass the libraries last (after the object file)
g++ -I/usr/include -L/usr/lib/x86_64-linux-gnu Main.o \
-lGL -lglut -lGLU -lGLEW -lX11 -lm -lrt -lpng -o main
The reason behind this is, that the linker only links symbols, that are currently undefined. If you pass the libraries before the object files, then there aren't any undefined symbols to be linked and compilation/linking will therefore fail.
The libraries need to come after your object files:
g++ -I/usr/include -L/usr/lib/x86_64-linux-gnu Main.o -lGL -lglut -lGLU -lGLEW -lX11 -lm -lrt -lpng -o main
I'm trying to compile the following c++ code that implements Context Tree Switching (More info on the download page):
Zip archive, 0.2 MB
which requires some boost libraries. I download the latest version from boost.org and built all libraries that needed building following the instructions on the website. I also modified the makefile included in the archive to add the boost lib path and boost_system, but I still get an error. Here's the makefile i'm using:
PROGRAM = cts
SOURCES = $(wildcard *.cpp)
OBJECTS = $(SOURCES:.cpp=.o)
CFLAGS = -Wall
LDFLAGS = -lboost_program_options -lboost_filesystem -lboost_system
$(PROGRAM): $(OBJECTS) Makefile
g++ $(CFLAGS) -L/home/users/mnembrini/opt/boost/lib $(LDFLAGS) -o $(PROGRAM) $(OBJECTS)
# Include known dependecies from -MMD
#-include $(OBJECTS:.o=.d)
%.o: %.cpp
g++ -MMD $(CFLAGS) -I/home/users/mnembrini/opt/boost/include -c $<
clean:
rm -f $(OBJECTS) *.d
.PHONY: clean
where boost is in ~/opt/boost (constains lib and include subdir). And here's the linking error:
mnembrini#meem:~/src/cts-v1 $ make
g++ -MMD -Wall -I/home/users/mnembrini/opt/boost/include -c ac.cpp
g++ -MMD -Wall -I/home/users/mnembrini/opt/boost/include -c cts.cpp
cts.cpp: In member function ‘virtual void SwitchingTree::update(bit_t)’:
cts.cpp:402:12: warning: variable ‘snc’ set but not used [-Wunused-but-set-variable]
cts.cpp: In member function ‘virtual double SwitchingTree::prob(bit_t)’:
cts.cpp:432:12: warning: variable ‘snc’ set but not used [-Wunused-but-set-variable]
g++ -MMD -Wall -I/home/users/mnembrini/opt/boost/include -c ctw.cpp
g++ -MMD -Wall -I/home/users/mnembrini/opt/boost/include -c icsilog.cpp
g++ -MMD -Wall -I/home/users/mnembrini/opt/boost/include -c main.cpp
g++ -MMD -Wall -I/home/users/mnembrini/opt/boost/include -c PowFast.cpp
g++ -Wall -L/home/users/mnembrini/opt/boost/lib -lboost_program_options -lboost_filesystem -lboost_system -o cts ac.o cts.o ctw.o icsilog.o main.o PowFast.o
cts.o: In function `__static_initialization_and_destruction_0(int, int)':
cts.cpp:(.text+0x1743): undefined reference to `boost::system::generic_category()'
cts.cpp:(.text+0x174f): undefined reference to `boost::system::generic_category()'
cts.cpp:(.text+0x175b): undefined reference to `boost::system::system_category()'
ctw.o: In function `__static_initialization_and_destruction_0(int, int)':
ctw.cpp:(.text+0xfcf): undefined reference to `boost::system::generic_category()'
ctw.cpp:(.text+0xfdb): undefined reference to `boost::system::generic_category()'
ctw.cpp:(.text+0xfe7): undefined reference to `boost::system::system_category()'
main.o: In function `showHelp()':
main.cpp:(.text+0x1c): undefined reference to `boost::program_options::operator<<(std::basic_ostream<char, std::char_traits<char> >&, boost::program_options::options_description const&)'
main.o: In function `initOptions(int, char**, boost::program_options::variables_map&)':
main.cpp:(.text+0x10f): undefined reference to `boost::program_options::options_description::add_options()'
main.cpp:(.text+0x129): undefined reference to `boost::program_options::options_description_easy_init::operator()(char const*, char const*)'
main.cpp:(.text+0x13e): undefined reference to `boost::program_options::options_description_easy_init::operator()(char const*, boost::program_options::value_semantic const*, char const*)'
main.cpp:(.text+0x153): undefined reference to `boost::program_options::options_description_easy_init::operator()(char const*, boost::program_options::value_semantic const*, char const*)'
main.cpp:(.text+0x166): undefined reference to `boost::program_options::options_description_easy_init::operator()(char const*, boost::program_options::value_semantic const*, char const*)'
main.cpp:(.text+0x1d6): undefined reference to `boost::program_options::store(boost::program_options::basic_parsed_options<char> const&, boost::program_options::variables_map&, bool)'
main.cpp:(.text+0x200): undefined reference to `boost::program_options::notify(boost::program_options::variables_map&)'
main.o: In function `__static_initialization_and_destruction_0(int, int)':
main.cpp:(.text+0x1f13): undefined reference to `boost::system::generic_category()'
main.cpp:(.text+0x1f1f): undefined reference to `boost::system::generic_category()'
[snip (2-3 screens like above)]
collect2: ld returned 1 exit status
make: *** [cts] Error 1
I'm using Gcc 4.6.3 on Ubuntu 12.04 64bit.
Place all the libraries after all the object files within the command line. The order is important here, unlike on some other operating systems.
You need to (just like n.m earlier wrote) make sure you have the correct order of the linking.
Basically some implementations care about what order you link object but also libraries.
If you link a library that hasnt yet been referenced by previous code it will be discarded. I remember coming up with a solution to hack in different (versions of) libraries in a program by referencing the same symbol but in an object linked after the first one and then re-link another library version:
-lyourprojwantingv1 -llibraryofv1 -lyourprojwantingv2 -llibraryofv2
Personally i think this is all just madness! (All of it!)
I've recently been trying to port a C++ application. I believe I have all of it's dependencies and such and it all compiles. But then, when it goes to link it I get a lot of weird undefined reference errors.
/usr/local/lib/libglibmm-2.4.so.7.0: undefined reference to `std::basic_istream<char, std::char_traits<char> >::seekg(long, std::_Ios_Seekdir)'
/usr/local/lib/libglibmm-2.4.so.7.0: undefined reference to `std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_S_empty_rep_storage'
/usr/local/lib/libxml++-2.6.so.0.1: undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::_S_empty_rep_storage'
/usr/local/lib/libxml++-2.6.so.0.1: undefined reference to `std::__default_alloc_template<true, 0>::deallocate(void*, unsigned long)'
What can cause this kind of errors? What do the linking errors mean? I can't really understand the complicated template error messages that gcc gives..
The linking command in it's entirety:
gmake[3]: Entering directory `/home/earlz/synfig-0.62.00/src/tool'
/bin/sh ../../libtool --tag=CXX --mode=link eg++ -I/usr/local/include/libxml++-2.6 -I/usr/local/lib/libxml++-2.6/include -I/usr/local/include/libxml2 -I/usr/local/include -I/usr/local/include/glibmm-2.4 -I/usr/local/lib/glibmm-2.4/include -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include/sigc++-2.0 -I/usr/local/lib/sigc++-2.0/include -I/usr/local/include -I/usr/local/include/sigc++-2.0 -I/usr/local/lib/sigc++-2.0/include -DSYNFIG_NO_DEPRECATED -DLOCALEDIR=\"/usr/local/share/locale\" -DNDEBUG -O2 -W -Wall -o synfig synfig-main.o ../synfig/libsynfig.la -L/usr/local/lib -lxml++-2.6 -lxml2 -lglibmm-2.4 -lgobject-2.0 -lglib-2.0 -lintl -liconv -lsigc-2.0 -lpthread -L/usr/local/lib -lsigc-2.0 -L/usr/local/lib -lintl -L/usr/local/lib -liconv -lpthread
libtool: link: eg++ -I/usr/local/include/libxml++-2.6 -I/usr/local/lib/libxml++-2.6/include -I/usr/local/include/libxml2 -I/usr/local/include -I/usr/local/include/glibmm-2.4 -I/usr/local/lib/glibmm-2.4/include -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/local/include/sigc++-2.0 -I/usr/local/lib/sigc++-2.0/include -I/usr/local/include -I/usr/local/include/sigc++-2.0 -I/usr/local/lib/sigc++-2.0/include -DSYNFIG_NO_DEPRECATED -DLOCALEDIR=\"/usr/local/share/locale\" -DNDEBUG -O2 -W -Wall -o .libs/synfig synfig-main.o -L../synfig/.libs -lsynfig -L/usr/local/lib -lxml++-2.6 -lxml2 -lm -lz -lglibmm-2.4 -lgmodule-2.0 -lgobject-2.0 -lglib-2.0 -lpcre -lsigc-2.0 -lintl -liconv -lpthread -Wl,-rpath,/usr/local/lib
Also, I do not get any kind of linking errors about missing files, just stuff about weird string and filestream stuff missing
Use g++ to link C++ applications, that add C++ standard libraries to the link phase.