0

I am trying to build C++ code using GCC 4.3.4 on SLES-15 and getting below error.

/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld: /lib/libc.so.6:
(*IND*+0x0): multiple definition of __umoddi3
/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld: /lib/libc.so.6:
(*IND*+0x0): multiple definition of __udivdi3
/usr/lib64/gcc/x86_64-suse-linux/4.3/../../../../x86_64-suse-linux/bin/ld: LicenseFile.o: in function `remove_dots(char const*)':

LicenseFile.cpp:(.text+0x16a8): undefined reference to `__gnu_cxx::__exchange_and_add(int*, int)'

I believe these both error a linked to same root cause, as same works on SLES-11 with GCC 4.3.4.

The default gcc version on SLES-15 is gcc 7 and I have installed gcc 4.3.4 and created softlink for g++-4.3.4 and gcc-4.3.4 as g++ and gcc respectively.

Below is the linker command

/usr/bin/g++ -m32 -pipe -O3 -fPIC -shared -Wl,-soname -Wl,libmgutil.so.5.6.4 -Wl,--no-undefined LicenseFile.o projectException.o projectResource.o projectServiceBase.o MessageStoreUtils.o OpenSSLInitializer.o ServiceConfigBase.o SmartHeapInit.o TimezoneManager.o Utils.o PriorityUtils.o stats_utils.o unix/projectService.o unix/projectLog.o unix/projectTrace.o unix/ServiceConfig.o -L/home/build/builds/project/build/Linux-i686-SLES11/Release -L/home/build/builds/project/ivy-dist/Linux-i686-SLES11-Release/lib -L/home/build/builds/project/ivy-dist/Linux-i686-SLES11/lib -L/home/build/builds/project/ivy-dist/Linux-i686-SLES11-Release/lib -L/home/build/builds/project/ivy-dist/Linux-i686-SLES11/lib -L/home/build/builds/project/projectSDK/proto/Linux-i686-SLES11-opt/lib -L/home/build/builds/project/build/Linux-i686-SLES11-opt/license/4.0.0-nightly/lib -L/home/build/builds/project/Shared/C/licensing/build/Linux-i686-SLES11/Release -L/home/build/builds/project/project/proto/Linux-i686-SLES11-opt/lib -Wl,--start-group -lCore -lssl -lcrypto -lmysqlclient -lboris -lapplic -llicense -lhermes -lpthread -lospace -ldl -Wl,--end-group -o /home/build/builds/project/build/Linux-i686-SLES11/Release/libmgutil.so.5.6.4

and the code from LicenseFile.cpp is (see the bold line where I believe it needs the _exchange_and_add() )

std::string td::string remove_dots(const char* host_id)
{
   std::string output;
   std::string str(host_id);
   for (size_t i = 0; i < str.size(); ++i) {
       if (str[i] != ':') **output += str[i];**
   }
   return output;
}
  • Did you mean to use `gcc` to compile C++ and link with libc and not (g++ and) libstdc++? – frippe Oct 12 '21 at 15:32
  • Does your version of the GCC libraries (libgcc/libstdc++ etc) match the version of your compiler? Does it work if you invoke the compiler explicitly as g++-4.3.4? – nneonneo Oct 12 '21 at 17:08
  • @frippe, No I am using g++-4.3.4 only to compile. – Rakesh Mehta Oct 13 '21 at 01:56
  • @nneonneo yes Iibgcc-4.3.4 and libstdc++-4.3.4 (we are using 32 bit) are also installed. the code uses -m32 to compile. – Rakesh Mehta Oct 13 '21 at 01:58
  • 3
    Alright, then you should probably include more of the compiler and linker output as well as the commands and options you're using. – frippe Oct 13 '21 at 08:41
  • Needs a [mcve]. – Robert Oct 14 '21 at 14:59
  • Please provide enough code so others can better understand or reproduce the problem. – Community Oct 14 '21 at 14:59
  • If you're mixing GCC < 5 with GCC >= 5 you might be running into std::string problems. It looks like `__exchange_and_add` is usually used as part of the old `std::string`. – o11c Oct 20 '21 at 02:57
  • @o11c I am not sure how its mixing "GCC < 5 with GCC >= 5"?. SLES-15 is a 64-bit OS with default GCC 7 and we are building the 32-bit code here using GCC 4.3.4. Is it possible that this issue could be linking and mixing of 32 bit vs 64 bit code. – Rakesh Mehta Oct 20 '21 at 04:01
  • @o11c as the function definition is __gnu_cxx::__exchange_and_add(int*, int) so its sure for "+=" – Rakesh Mehta Oct 20 '21 at 07:04
  • Compare results of **ld -V** on both OS. SLES-11 it gives below output:. GNU ld (GNU Binutils; SUSE Linux Enterprise 11) 2.20.0.20100122-0.7.9 Supported emulations: elf_x86_64 elf_i386 i386linux elf_l1om SLES-15 it has many emulation but missing **i386linux**. top few lines for sles-15 GNU ld (GNU Binutils; SUSE Linux Enterprise 15) 2.35.1.20201123-7.18 Supported emulations: elf_x86_64 elf32_x86_64 elf_i386 elf_iamcu elf_l1om elf_k1om aarch64linux – Rakesh Mehta Oct 20 '21 at 10:50
  • @o11c so If its the issue of mixing GCC <5 and GCC >=5, then what is the solution? – Rakesh Mehta Oct 27 '21 at 10:05
  • @RakeshMehta stop using an ancient version of GCC? – o11c Oct 27 '21 at 15:38
  • @o11c moving to higher GCC required a lot of code change, so its not feasible for the moment. On displaying the symbols for /usr/lib/libstdc++.so.6 it has _ __gnu_cxx::__exchange_and_add(int volatile*, int)_ but not **__gnu_cxx::__exchange_and_add(int *, int)** – Rakesh Mehta Oct 29 '21 at 14:32

0 Answers0