I want to compile a very simple C++ program. On the first machine the compilation process works fine and also the program runs fine. However, on the second linux machine I have some libraries not found problems. The compilation process looks like this:
gcc -o WebPageCrawler -lawesomium-1-7 -Wall WebPageCrawler.cc
/tmp/ccoLVzvo.o: In function `main':
WebPageCrawler.cc:(.text+0x28): undefined reference to `std::cout'
WebPageCrawler.cc:(.text+0x2d): undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
...even more errors...
As you can see the compiler even cannot find stdlibs and the other referenced library awesomium (a headless browser) is also not available. However, the corresponding libs can all be found in /usr/lib. So, there must be something else wrong but I don't know what it might be.
My linux version is
uname -a
Linux Ubuntu-1204-precise-64-minimal 3.2.0-39-generic
I'd appriciate any help. Thx.
UPDATE:
When using g++ I get:
g++ -o WebPageCrawler -lawesomium-1-7 -Wall WebPageCrawler.cc
Unable to exec g++.real: No such file or directory
However, on the other machine I used gcc instead of g++ and it works fine there.
UPDATE2:
Okay, now I'm able to get a least the problem of the stdlibs resolved. I did this by further installing:
apt-get install build-essential g++
However, now the awesomium libs are still not found:
/opt/AwesomiumCrawler # g++ -v -o WebPageCrawler -lawesomium-1-7 -Wall WebPageCrawler.cc
Using built-in specs.
COLLECT_GCC=g++.real
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)
COLLECT_GCC_OPTIONS='-v' '-o' 'WebPageCrawler' '-Wall' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.6/cc1plus -quiet -v -imultilib . -imultiarch x86_64-linux-gnu -D_GNU_SOURCE WebPageCrawler.cc -quiet -dumpbase WebPageCrawler.cc -mtune=generic -march=x86-64 -auxbase WebPageCrawler -Wall -version -fstack-protector -o /tmp/ccGGfqAI.s
GNU C++ (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (x86_64-linux-gnu)
compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=127439
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/include/c++/4.6
/usr/include/c++/4.6/x86_64-linux-gnu/.
/usr/include/c++/4.6/backward
/usr/lib/gcc/x86_64-linux-gnu/4.6/include
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
GNU C++ (Ubuntu/Linaro 4.6.3-1ubuntu5) version 4.6.3 (x86_64-linux-gnu)
compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=127439
Compiler executable checksum: 65b5171ac1bd7b3f07dbea6bdb24be3d
COLLECT_GCC_OPTIONS='-v' '-o' 'WebPageCrawler' '-Wall' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
as --64 -o /tmp/cctijQGE.o /tmp/ccGGfqAI.s
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'WebPageCrawler' '-Wall' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
/usr/lib/gcc/x86_64-linux-gnu/4.6/collect2 --sysroot=/ --build-id --no-add-needed --as-needed --eh-frame-hdr -m elf_x86_64 --hash-style=gnu -dynamic-linker /lib64/ld-linux-x86-64.so.2 -z relro -o WebPageCrawler /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.6/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.6 -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.6/../../.. -lawesomium-1-7 /tmp/cctijQGE.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.6/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crtn.o
/tmp/cctijQGE.o: In function `main':
WebPageCrawler.cc:(.text+0x8d): undefined reference to `Awesomium::WebConfig::WebConfig()'
WebPageCrawler.cc:(.text+0xc7): undefined reference to `Awesomium::WebString::operator=(Awesomium::WebString const&)'
WebPageCrawler.cc:(.text+0xd6): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0xe5): undefined reference to `Awesomium::WebCore::Initialize(Awesomium::WebConfig const&)'
WebPageCrawler.cc:(.text+0x140): undefined reference to `Awesomium::WebURL::WebURL(Awesomium::WebString const&)'
WebPageCrawler.cc:(.text+0x14c): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x1ed): undefined reference to `Awesomium::WebString::CreateFromUTF8(char const*, unsigned int)'
WebPageCrawler.cc:(.text+0x203): undefined reference to `Awesomium::WebString::CreateFromUTF8(char const*, unsigned int)'
WebPageCrawler.cc:(.text+0x23c): undefined reference to `Awesomium::JSValue::ToString() const'
WebPageCrawler.cc:(.text+0x259): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x27b): undefined reference to `Awesomium::WebCore::Shutdown()'
WebPageCrawler.cc:(.text+0x28c): undefined reference to `Awesomium::JSValue::~JSValue()'
WebPageCrawler.cc:(.text+0x298): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x2a4): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x2b0): undefined reference to `Awesomium::WebURL::~WebURL()'
WebPageCrawler.cc:(.text+0x2dd): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x2ee): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x2ff): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x310): undefined reference to `Awesomium::JSValue::~JSValue()'
WebPageCrawler.cc:(.text+0x321): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x332): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text+0x343): undefined reference to `Awesomium::WebURL::~WebURL()'
/tmp/cctijQGE.o: In function `Update(int)':
WebPageCrawler.cc:(.text+0x372): undefined reference to `Awesomium::WebCore::instance()'
/tmp/cctijQGE.o: In function `Awesomium::ToString(Awesomium::WebString const&)':
WebPageCrawler.cc:(.text._ZN9Awesomium8ToStringERKNS_9WebStringE[Awesomium::ToString(Awesomium::WebString const&)]+0x25): undefined reference to `Awesomium::WebString::IsEmpty() const'
WebPageCrawler.cc:(.text._ZN9Awesomium8ToStringERKNS_9WebStringE[Awesomium::ToString(Awesomium::WebString const&)]+0x4d): undefined reference to `Awesomium::WebString::ToUTF8(char*, unsigned int) const'
WebPageCrawler.cc:(.text._ZN9Awesomium8ToStringERKNS_9WebStringE[Awesomium::ToString(Awesomium::WebString const&)]+0x75): undefined reference to `Awesomium::WebString::ToUTF8(char*, unsigned int) const'
/tmp/cctijQGE.o: In function `Awesomium::WSLit(char const*)':
WebPageCrawler.cc:(.text._ZN9Awesomium5WSLitEPKc[Awesomium::WSLit(char const*)]+0x2d): undefined reference to `Awesomium::WebString::CreateFromUTF8(char const*, unsigned int)'
/tmp/cctijQGE.o: In function `Awesomium::WebConfig::~WebConfig()':
WebPageCrawler.cc:(.text._ZN9Awesomium9WebConfigD2Ev[_ZN9Awesomium9WebConfigD5Ev]+0x19): undefined reference to `Awesomium::WebStringArray::~WebStringArray()'
WebPageCrawler.cc:(.text._ZN9Awesomium9WebConfigD2Ev[_ZN9Awesomium9WebConfigD5Ev]+0x29): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text._ZN9Awesomium9WebConfigD2Ev[_ZN9Awesomium9WebConfigD5Ev]+0x39): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text._ZN9Awesomium9WebConfigD2Ev[_ZN9Awesomium9WebConfigD5Ev]+0x49): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text._ZN9Awesomium9WebConfigD2Ev[_ZN9Awesomium9WebConfigD5Ev]+0x59): undefined reference to `Awesomium::WebString::~WebString()'
WebPageCrawler.cc:(.text._ZN9Awesomium9WebConfigD2Ev[_ZN9Awesomium9WebConfigD5Ev]+0x69): undefined reference to `Awesomium::WebString::~WebString()'
/tmp/cctijQGE.o:WebPageCrawler.cc:(.text._ZN9Awesomium9WebConfigD2Ev[_ZN9Awesomium9WebConfigD5Ev]+0x79): more undefined references to `Awesomium::WebString::~WebString()' follow
collect2: ld returned 1 exit status
As already mentioned the libs lie in
/usr/lib # ls -l *awe*
-rwxr-xr-x 1 root root 8032 Feb 12 18:49 awesomium_process
lrwxrwxrwx 1 root root 21 Feb 12 18:49 libawesomium-1-7.so -> libawesomium-1-7.so.2
lrwxrwxrwx 1 root root 23 Feb 12 18:49 libawesomium-1-7.so.2 -> libawesomium-1-7.so.2.0
-rwxr-xr-x 1 root root 63475481 Feb 12 18:49 libawesomium-1-7.so.2.0
The command to compile C++ code is g++, not gcc.
They're both part of the same collection, but the g++ command adds some extra options; in particular, it implicitly links the C++ standard library.
When compiling with -c, to generate just an object file and not invoke the linker, it may not matter -- but you're generating an executable, which means the linker needs to know about the dependency on the C++ standard library.
UPDATE: And now that you've updated the question: You may need to install g++ (on your system, apt-get install build-essential g++).
And now you have a different problem: g++ can't find the "awesomium" libraries. The libraries are in /usr/lib, so you shouldn't need to specify a -L option. The problem is that the -l option needs to follow the file that depends on it.
The linker processes its command-line arguments in order, keeping track of which symbols still need to be resolved and resolving any unresolved symbols in objects or libraries that it processes later.
So rather than:
g++ -o WebPageCrawler -lawesomium-1-7 -Wall WebPageCrawler.cc
try:
g++ -Wall WebPageCrawler.cc -lawesomium-1-7 -o WebPageCrawler
That specific order isn't mandatory, but it should work.
Related
I have system with CentOS 6.4 and it comes with GNU Fortran (GCC) 4.4.7 20120313 (Red Hat 4.4.7-18).
I am doing quadrupule precision calculation and for that I installed devtoolset-6 w/o a problem. Since the system has a default gcc/gfortran installed, i cleared the shell with
env -i bash
and following that i set the devtoolset-6 environment
scl enable devtoolset-6 bash
If i check the installed gcc and gfortran version, they are as following
gcc (GCC) 6.3.1 20170216 (Red Hat 6.3.1-3)
GNU Fortran (GCC) 6.3.1 20170216 (Red Hat 6.3.1-3)
so far so good. I also have a testing example given below
implicit double precision(a-h,o-z)
print * , ' i:'
read(5,*) i
if(i.le.0) stop
a=i
b=sqrt(a)
print * , b
c=b*b
print * , c
end
compiled with
gfortran -fdefault-real-8 -o test.exe test.F
When i try to compile i am getting the following error
(.text+0x20): undefined reference to main'
/tmp/cc7n6vIv.o: In functionljacoeff_':test.F:(.text+0xf0): undefined reference to _gfortran_transfer_real128_write'
test.F:(.text+0x16b): undefined reference to_gfortran_transfer_complex128_write'
test.F:(.text+0x1ea): undefined reference to `_gfortran_transfer_complex128_write'
collect2: error: ld returned 1 exit status
At first, i thought the _gfortran_transfer_real128_write function is not defined and checked the library comes with devtoolset-6 using default "nm" command and indeed that function is defined in libgfortran.a. After some debugging and more debugging i discovered the "-v" option and recompiled the code, then noticed something confusing looks like ld checks the system old libraries instead of the one comes with devtoolset-6. The LIBRARY_PATH includes the /usr/lib/../lib64/ folder and that causes the error. In any case, If the linker couldn't find these function, it should also check the devtoolset-6 libraries. Looks like this doesn't happen. How could i resolve this linking error?
Driving: gfortran -v -fdefault-real-8 -o test.exe test.F -l gfortran
-l m -shared-libgcc Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/lto-wrapper
Target: x86_64-redhat-linux Configured with: ../configure
--enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-6/root/usr --mandir=/opt/rh/devtoolset-6/root/usr/share/man --infodir=/opt/rh/devtoolset-6/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --disable-libgcj --with-default-libstdcxx-abi=gcc4-compatible --with-isl=/builddir/build/BUILD/gcc-6.3.1-20170216/obj-x86_64-redhat-linux/isl-install
--enable-libmpx --with-mpc=/builddir/build/BUILD/gcc-6.3.1-20170216/obj-x86_64-redhat-linux/mpc-install
--with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux Thread model: posix gcc version 6.3.1 20170216 (Red Hat 6.3.1-3) (GCC)
COLLECT_GCC_OPTIONS='-v' '-fdefault-real-8' '-o' 'test.exe'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/f951
test.F -ffixed-form -cpp=/tmp/ccjQiTpi.f90 -quiet -v test.F -quiet
-dumpbase test.F -mtune=generic -march=x86-64 -auxbase test -version -fdefault-real-8 -fintrinsic-modules-path /opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/finclude
-o /tmp/cceJeO1o.s GNU Fortran (GCC) version 6.3.1 20170216 (Red Hat 6.3.1-3) (x86_64-redhat-linux) compiled by GNU C version 6.3.1 20170216 (Red Hat 6.3.1-3), GMP version 4.3.1, MPFR version 2.4.1, MPC
version 0.8.1, isl version 0.14 or 0.13 GGC heuristics: --param
ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring
nonexistent directory
"/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/include-fixed"
ignoring nonexistent directory
"/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here: /opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/finclude
/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/include
/usr/local/include /opt/rh/devtoolset-6/root/usr/include
/usr/include End of search list. GNU Fortran2008 (GCC) version 6.3.1
20170216 (Red Hat 6.3.1-3) (x86_64-redhat-linux) compiled by GNU C
version 6.3.1 20170216 (Red Hat 6.3.1-3), GMP version 4.3.1, MPFR
version 2.4.1, MPC version 0.8.1, isl version 0.14 or 0.13 GGC
heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-v' '-fdefault-real-8' '-o' 'test.exe'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/as
-v --64 -o /tmp/cc7n6vIv.o /tmp/cceJeO1o.s GNU assembler version 2.27 (x86_64-redhat-linux) using BFD version version 2.27-8.el6 Reading
specs from
/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/libgfortran.spec
rename spec lib to liborig COLLECT_GCC_OPTIONS='-v' '-fdefault-real-8'
'-o' 'test.exe' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
COMPILER_PATH=/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/:/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/:/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/:/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/:/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/
LIBRARY_PATH=/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/:/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:
/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-fdefault-real-8' '-o' 'test.exe'
'-shared-libgcc' '-mtune=generic' '-march=x86-64'
/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/collect2
-plugin /opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/liblto_plugin.so
-plugin-opt=/opt/rh/devtoolset-6/root/usr/libexec/gcc/x86_64-redhat-linux/6.3.1/lto-wrapper
-plugin-opt=-fresolution=/tmp/ccQAAlqC.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lquadmath -plugin-opt=-pass-through=-lm -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o test.exe /usr/lib/../lib64/crt1.o
/usr/lib/../lib64/crti.o
/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/crtbegin.o
-L/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1 -L/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../../../lib64
-L/lib/../lib64 -L/usr/lib/../lib64 -L/opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/../../..
/tmp/cc7n6vIv.o -lgfortran -lm -lgcc_s -lgcc -lquadmath -lm -lgcc_s
-lgcc -lc -lgcc_s -lgcc /opt/rh/devtoolset-6/root/usr/lib/gcc/x86_64-redhat-linux/6.3.1/crtend.o
/usr/lib/../lib64/crtn.o /usr/lib/../lib64/crt1.o: In function
_start': (.text+0x20): undefined reference tomain' /tmp/cc7n6vIv.o:
In function ljacoeff_': test.F:(.text+0xf0): undefined reference to
_gfortran_transfer_real128_write' test.F:(.text+0x16b): undefined
reference to _gfortran_transfer_complex128_write'
test.F:(.text+0x1ea): undefined reference to
_gfortran_transfer_complex128_write' collect2: error: ld returned 1
exit status
I am trying to built some sample gtk+ examples that came with the gtk+ sources. My need was only to have a gtk+ UI to a C program. I went about downloading and building gtk+ but realised (through SO) that this was not needed and that I only need libgtk-3-dev.
sudo apt-get install libgtk-3-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libgtk-3-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 373 not upgraded.
EDIT: NOTE: Issue is not with the sequence of libraries or includes as I am using the makefile that came with gtk+.
I tried compiling an example that I had with the gtk+ code I downloaded. I get the below errors. The other queries on this topic mentioned that the order of the flags matter, but in this case I have used the makefile that came with the sources. Should I be installing something more than the libgtk-3-dev library (running on Ubuntu 14.04 ).
~/gtk/examples/application1$ make -f Makefile.example
cc -c -o main.o -pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng12 main.c
cc -c -o exampleapp.o -pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng12 exampleapp.c
cc -c -o exampleappwin.o -pthread -I/usr/include/gtk-3.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/pango-1.0 -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/pixman-1 -I/usr/include/libpng12 exampleappwin.c
cc -o exampleapp -lgtk-3 -lgdk-3 -latk-1.0 -lgio-2.0 -lpangocairo-1.0 -lgdk_pixbuf-2.0 -lcairo-gobject -lpango-1.0 -lcairo -lgobject-2.0 -lglib-2.0 main.o exampleapp.o exampleappwin.o
main.o: In function main':
main.c:(.text+0x11): undefined reference tog_application_get_type'
main.c:(.text+0x24): undefined reference to g_type_check_instance_cast'
main.c:(.text+0x35): undefined reference tog_application_run'
exampleapp.o: In function example_app_class_intern_init':
exampleapp.c:(.text+0x14): undefined reference tog_type_class_peek_parent'
exampleapp.c:(.text+0x36): undefined reference to g_type_class_adjust_private_offset'
exampleapp.o: In functionexample_app_get_type':
exampleapp.c:(.text+0x66): undefined reference to g_once_init_enter'
exampleapp.c:(.text+0x84): undefined reference tog_intern_static_string'
exampleapp.c:(.text+0x8c): undefined reference to gtk_application_get_type'
exampleapp.c:(.text+0xb4): undefined reference tog_type_register_static_simple'
exampleapp.c:(.text+0xc9): undefined reference to g_once_init_leave'
exampleapp.o: In functionexample_app_activate':
exampleapp.c:(.text+0x104): undefined reference to g_type_check_instance_cast'
exampleapp.c:(.text+0x115): undefined reference togtk_window_get_type'
exampleapp.c:(.text+0x127): undefined reference to g_type_check_instance_cast'
exampleapp.c:(.text+0x12f): undefined reference togtk_window_present'
exampleapp.o: In function example_app_open':
exampleapp.c:(.text+0x14d): undefined reference togtk_application_get_type'
exampleapp.c:(.text+0x15f): undefined reference to g_type_check_instance_cast'
exampleapp.c:(.text+0x167): undefined reference togtk_application_get_windows'
exampleapp.c:(.text+0x18c): undefined reference to g_type_check_instance_cast'
exampleapp.c:(.text+0x1a9): undefined reference tog_type_check_instance_cast'
exampleapp.c:(.text+0x1f5): undefined reference to gtk_window_get_type'
exampleapp.c:(.text+0x207): undefined reference tog_type_check_instance_cast'
exampleapp.c:(.text+0x20f): undefined reference to gtk_window_present'
exampleapp.o: In functionexample_app_class_init':
exampleapp.c:(.text+0x222): undefined reference to g_application_get_type'
exampleapp.c:(.text+0x234): undefined reference tog_type_check_class_cast'
exampleapp.c:(.text+0x244): undefined reference to g_application_get_type'
exampleapp.c:(.text+0x256): undefined reference tog_type_check_class_cast'
exampleapp.o: In function example_app_new':
exampleapp.c:(.text+0x294): undefined reference tog_object_new'
exampleappwin.o: In function example_app_window_class_intern_init':
exampleappwin.c:(.text+0x14): undefined reference tog_type_class_peek_parent'
exampleappwin.c:(.text+0x36): undefined reference to g_type_class_adjust_private_offset'
exampleappwin.o: In functionexample_app_window_get_type':
exampleappwin.c:(.text+0x66): undefined reference to g_once_init_enter'
exampleappwin.c:(.text+0x84): undefined reference tog_intern_static_string'
exampleappwin.c:(.text+0x8c): undefined reference to gtk_application_window_get_type'
exampleappwin.c:(.text+0xb4): undefined reference tog_type_register_static_simple'
exampleappwin.c:(.text+0xc9): undefined reference to g_once_init_leave'
exampleappwin.o: In functionexample_app_window_new':
exampleappwin.c:(.text+0x117): undefined reference to `g_object_new'
collect2: error: ld returned 1 exit status
make: *** [exampleapp] Error 1
For whatever reason the Makefile in the GTK+ 3.20 source tree is broken; as per n.m.'s comment. There might already be a bugfix, if not a fix, for that.
But you can't use GTK+ 3.20 with the GTK+ 3.10 that comes with Ubuntu 14.04 LTS. You're better off using the GTK+ 3.10 examples and source code. If you really want to use a newer version of GTK+, you can use jhbuild to set up an environment separate from the rest of the system (typically in /opt/gnome) to build a newer versions of GTK+ into.
I am trying to build a software package from source with make in Centos 6.5 which was successfully built in Fedora 8.
I made a few changes to the files and downgrade a few dependencies in Centos.
When I do make, I get a linker error:
/home/wjn/Desktop/samPro/src/graphEdit.o:
In function `GW::graphEdit::setPoints(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)': graphEdit.cpp:(.text+0x88): undefined reference to `bool GW::GraphUtils::create<GW::MathVector<double, 3, GW::MathVectorColumn>
>(GW::Graph<double, 3, GW::GraphColumn>&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, char, char, char)' collect2: ld returned 1 exit status
I checked the gcc command initiated by make, it is:
/usr/bin/g++ -D_GNU_SOURCE -O3 -mfpmath=sse -finline-limit=1000 -shared -Xlinker --no-undefined -Wl,-soname,libGraphImg.so
-o /home/wjn/Desktop/samPro/lib/graphImg.so /home/wjn/Desktop/samPro/src/graphType.o
/home/wjn/Desktop/samPro/src/graphCalibration.o
/home/wjn/Desktop/samPro/src/graphEdit.o
/home/wjn/Desktop/samPro/src/imgMorph.o
-L/home/wjn/Desktop/samPro/lib -Wl,
-rpath-link=/home/wjn/Desktop/samPro/lib -Wl,
-Bdynamic -lpthread -lm -lc
So I check graphUtils.h and graphUtils.cpp, bool GW::GraphUtils::create is properly defined but there is no graphUtils.o.
It is perfectly built in Fedora 8, so I am guessing it is a compiler version problem?
Centos has GCC 4.4.7 and Fedora has 4.1.2, could this be the problem? What can I do to solve this if I don't want to use the old GCC to build it.
So, I upgraded to Yosemite and also updated gcc to gcc-4.9. Now nothing works. Even a basic C program like this:
#include "stdio.h"
void main() {
printf("woh!");
}
The details of gcc -v a.c is below. The basic error is:
Undefined symbols for architecture x86_64:
"start", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
Here is my configuration for CC, clang and gcc.
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/4.9.2/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/lto-wrapper
Target: x86_64-apple-darwin14.0.0
Configured with: ../configure --build=x86_64-apple-darwin14.0.0 --prefix=/usr/local/Cellar/gcc/4.9.2 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-4.9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-cloog=/usr/local/opt/cloog --with-isl=/usr/local/opt/isl --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --disable-werror --with-pkgversion='Homebrew gcc 4.9.2' --with-bugurl=https://github.com/Homebrew/homebrew/issues --enable-plugin --disable-nls --enable-multilib
Thread model: posix
gcc version 4.9.2 (Homebrew gcc 4.9.2)
I had created links for gcc to gcc-4.9 which was installed successfully using Homebrew. I have run brew doctor and received no issues. Command Line Tools was updated using code-select -install
Gautams-MacBook-Pro:~ gautamrege$ ls -l /usr/local/bin/gcc
lrwxrwxr-x 1 gautamrege admin 22 Nov 14 20:14 /usr/local/bin/gcc# -> /usr/local/bin/gcc-4.9
Gautams-MacBook-Pro:~ gautamrege$ ls -l /usr/local/bin/gcc-4.9
lrwxrwxr-x 1 gautamrege admin 31 Nov 14 20:14 /usr/local/bin/gcc-4.9# -> ../Cellar/gcc/4.9.2/bin/gcc-4.9
These are my CC and clang versions (basically the same)
Gautams-MacBook-Pro:~ gautamrege$ CC -v
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
Gautams-MacBook-Pro:~ gautamrege$ clang -c
clang: error: no input files
Gautams-MacBook-Pro:~ gautamrege$ clang -v
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin14.0.0
Thread model: posix
Finally, here is the detailed log using gcc -v.
$ gcc -v a.c
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/Cellar/gcc/4.9.2/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/lto-wrapper
Target: x86_64-apple-darwin14.0.0
Configured with: ../configure --build=x86_64-apple-darwin14.0.0 --prefix=/usr/local/Cellar/gcc/4.9.2 --enable-languages=c,c++,objc,obj-c++,fortran --program-suffix=-4.9 --with-gmp=/usr/local/opt/gmp --with-mpfr=/usr/local/opt/mpfr --with-mpc=/usr/local/opt/libmpc --with-cloog=/usr/local/opt/cloog --with-isl=/usr/local/opt/isl --with-system-zlib --enable-version-specific-runtime-libs --enable-libstdcxx-time=yes --enable-stage1-checking --enable-checking=release --enable-lto --disable-werror --with-pkgversion='Homebrew gcc 4.9.2' --with-bugurl=https://github.com/Homebrew/homebrew/issues --enable-plugin --disable-nls --enable-multilib
Thread model: posix
gcc version 4.9.2 (Homebrew gcc 4.9.2)
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.10.0' '-v' '-mtune=core2'
/usr/local/Cellar/gcc/4.9.2/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/cc1 -quiet -v -D__DYNAMIC__ a.c -fPIC -quiet -dumpbase a.c -mmacosx-version-min=10.10.0 -mtune=core2 -auxbase a -version -o /var/folders/dr/kc0cps51533gqx5zm8gv33x80000gn/T//ccvx7Ydq.s
GNU C (Homebrew gcc 4.9.2) version 4.9.2 (x86_64-apple-darwin14.0.0)
compiled by GNU C version 4.9.2, GMP version 6.0.0, MPFR version 3.1.2-p10, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/Cellar/gcc/4.9.2/include"
ignoring nonexistent directory "/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../../x86_64-apple-darwin14.0.0/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/include
/usr/local/include
/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/include-fixed
/usr/include
/System/Library/Frameworks
/Library/Frameworks
End of search list.
GNU C (Homebrew gcc 4.9.2) version 4.9.2 (x86_64-apple-darwin14.0.0)
compiled by GNU C version 4.9.2, GMP version 6.0.0, MPFR version 3.1.2-p10, MPC version 1.0.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: f90e36a64a568856fa161772b1b4076f
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.10.0' '-v' '-mtune=core2'
as -arch x86_64 -force_cpusubtype_ALL -o /var/folders/dr/kc0cps51533gqx5zm8gv33x80000gn/T//cckdbo1t.o /var/folders/dr/kc0cps51533gqx5zm8gv33x80000gn/T//ccvx7Ydq.s
COMPILER_PATH=/usr/local/Cellar/gcc/4.9.2/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2/libexec/gcc/x86_64-apple-darwin14.0.0/:/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/
LIBRARY_PATH=/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/:/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../../:/usr/lib/
COLLECT_GCC_OPTIONS='-mmacosx-version-min=10.10.0' '-v' '-mtune=core2'
/usr/local/Cellar/gcc/4.9.2/libexec/gcc/x86_64-apple-darwin14.0.0/4.9.2/collect2 -dynamic -arch x86_64 -macosx_version_min 10.10.0 -weak_reference_mismatches non-weak -o a.out -L/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2 -L/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../.. /var/folders/dr/kc0cps51533gqx5zm8gv33x80000gn/T//cckdbo1t.o -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem -v
collect2 version 4.9.2
/usr/bin/ld -dynamic -arch x86_64 -macosx_version_min 10.10.0 -weak_reference_mismatches non-weak -o a.out -L/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2 -L/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2/../../.. /var/folders/dr/kc0cps51533gqx5zm8gv33x80000gn/T//cckdbo1t.o -no_compact_unwind -lSystem -lgcc_ext.10.5 -lgcc -lSystem -v
#(#)PROGRAM:ld PROJECT:ld64-136
configured to support archs: armv6 armv7 armv7s i386 x86_64
Library search paths:
/usr/local/Cellar/gcc/4.9.2/lib/gcc/x86_64-apple-darwin14.0.0/4.9.2
/usr/local/Cellar/gcc/4.9.2/lib
/usr/lib
/usr/local/lib
Framework search paths:
/Library/Frameworks/
/System/Library/Frameworks/
Undefined symbols for architecture x86_64:
"start", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
I'm pretty sure I am making some basic mistake.Needless to day, all other package installations are failing because of this same error. Any ideas?
Copying information from comments to this Community Wiki answer.
Tim Smith pointed out that the key to this problem is to run:
sudo xcode-select -s /Library/Developer/CommandLineTools/
This makes sure that clang invokes the XCode 6 version of clang.
After upgrading the boost libraries form version 1.52 to 1.53 I get the following linker error when building with GCC under Linux. The same application builds fine under Windows with VC++10 and boost 1.53.
Invoking: GCC C++ Linker
g++ -L"/home/robert/boost_1_53_0/stage/lib" -L/usr/lib -o "MyApp" ./myObjectFile.o -lboost_log_setup-mt-s -lboost_log-mt-s -lboost_thread-mt-s -lboost_system-mt-s -lboost_regex-mt-s -lcryptopp -lboost_date_time-mt-s -lpthread -ldl -lboost_filesystem-mt-s
/home/robert/boost_1_53_0/stage/lib/libboost_thread-mt-s.a(thread.o): In function `boost::this_thread::hiden::sleep_for(timespec const&)':
thread.cpp:(.text+0xc10): undefined reference to `clock_gettime'
/home/robert/boost_1_53_0/stage/lib/libboost_thread-mt-s.a(thread.o): In function `boost::this_thread::hiden::sleep_until(timespec const&)':
thread.cpp:(.text+0x1425): undefined reference to `clock_gettime'
thread.cpp:(.text+0x14cd): undefined reference to `clock_gettime'
thread.cpp:(.text+0x159c): undefined reference to `clock_gettime'
thread.cpp:(.text+0x1684): undefined reference to `clock_gettime'
/home/robert/boost_1_53_0/stage/lib/libboost_thread-mt-s.a(thread.o):thread.cpp:(.text+0x176e): more undefined references to `clock_gettime' follow
collect2: error: ld returned 1 exit status
I built the boost libraries like this:
./bootstrap.sh --with-toolset=gcc
./b2 --layout=tagged variant=debug,release link=static runtime-link=static cxxflags=-std=c++0x
My GCC version is 4.7.2
It basically says that clock_gettime function is not found by the linker. This function is in rt library, so add -lrt to the linker command line.