Reputation: 353
I'm not experienced at building with gcc at all and now require some help. I've a code that is being built with the following options
gcc \
-g myCode.C \
-O \
-o myCode \
-I. \
-L. \
-L/usr/lib64 \
-lstdc++ \
-Wreturn-type \
-Wswitch \
-Wcomment \
-Wformat \
-Wchar-subscripts \
-Wparentheses \
-Wpointer-arith \
-Wcast-qual \
-Woverloaded-virtual \
-Wno-write-strings /usr/lib64/libm.so \
-Wno-deprecated
When compiling myCode.C
on redhat 6 machine it is not working on older versions of the OS throwing errors
/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.9' not found
/usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.11' not found
To fix this issue, I've tried to add -static
build option to make all dynamic linking libraries as static, but have some build error which i dont understand :(
/usr/bin/ld: attempted static link of dynamic object `/usr/lib64/libm.so'
collect2: ld returned 1 exit status
How do I make my code to work on older version of redhat rather than only on 6 and newer ?? what build options should I add/remove ?
Upvotes: 4
Views: 24052
Reputation: 3494
/usr/lib64/libm.so
is a dynamic library. Since you link explicitly with it, -static
doesn't force using the static version (libm.a
)
You are trying to compile a C++ program so you should use g++. Passing the libstdc++
and libm
libraries is not needed then. Also /usr/lib64
should be in your standard link path so is not needed.
So you should use:
g++ \
-static \
-g myCode.C \
-O \
-o myCode \
-I. \
-L. \
-Wreturn-type \
-Wswitch \
-Wcomment \
-Wformat \
-Wchar-subscripts \
-Wparentheses \
-Wpointer-arith \
-Wcast-qual \
-Woverloaded-virtual \
-Wno-write-strings \
-Wno-deprecated
Upvotes: 6