0

I'm a newbie to C++ and NetBeans. Recently I have been trying to set up NetBeans for my C++ project, which was developed by one of my colleagues 5 to 10 years ago, but I kept receiving compiler errors. We used trilinos for numerical simulation. There is no compiler error in my colleague's Linux desktop, but somehow I just couldn't set up NetBeans in my virtual Linux via UTM.

enter image description here

As shown above, I followed the NetBeans settings in his Linux desktop and added a library file lib/trilinos/lib/libepetra.so.12 into the Linker > Libraries. Then I right clicked the project and selected Build, now here is the compiler error message.

cd '/root/Venus/Folders/MyProject'
/usr/bin/gmake -f Makefile CONF=Serial
"/usr/bin/gmake" -f nbproject/Makefile-Serial.mk QMAKE= SUBPROJECTS= .build-conf
gmake[1]: Entering directory '/root/Venus/Folders/MyProject'
"/usr/bin/gmake"  -f nbproject/Makefile-Serial.mk dist/MyProject
gmake[2]: Entering directory '/root/Venus/Folders/MyProject'
mkdir -p dist
g++     -o dist/MyProject build/Serial/GNU-Linux/main.o -Llib/trilinos/lib -lboost_system lib/trilinos/lib/libepetra.so.12

/usr/bin/ld: lib/trilinos/lib/libepetra.so.12: error adding symbols: file in wrong format

collect2: error: ld returned 1 exit status

gmake[2]: *** [nbproject/Makefile-Serial.mk:65: dist/MyProject] Error 1
gmake[2]: Leaving directory '/root/Venus/Folders/MyProject'
gmake[1]: *** [nbproject/Makefile-Serial.mk:59: .build-conf] Error 2
gmake[1]: Leaving directory '/root/Venus/Folders/MyProject'
gmake: *** [nbproject/Makefile-impl.mk:40: .build-impl] Error 2

BUILD FAILED (exit value 2, total time: 157ms)

What I have checked

  1. Path: the path is correct. I also selected Relative to Run Directory for Runtime Library Search Path. If the path is incorrect, the compiler error message would be:

gmake2: *** No rule to make target 'lib/trilinos/liba/libepetra.so.12', needed by 'dist/MyProject'. Stop.

(the folder ../liba/.. doesn't exist)

  1. g++ and C++ version: G++ is 11.3.0 and C++ is C++11. However, the g++ on my colleague's desktop is 5.4.0.

g++ (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0 (g++ on my Linux)

  1. NetBeans version: My NetBeans is version 14, while the one on my colleague's desktop is NetBeans 7 or 8. It's a very old version.

What I am still trying to check:

  1. Trilinos version: I still don't know how to check it.

Could someone please help me? I have been struggling with it for several days. I would truly appreciate it! Thank you.

Zureas
  • 53
  • 5
  • Does the `g++` command, executed in your command prompt, produce the same error? This issue seems to have nothing to do with NetBeans and everything to do with how your specific version of g++ recognizes the file `libepetra.so.12`. – Drew Dormann Jun 27 '23 at 19:42
  • _"lib/trilinos/lib/libepetra.so.12: error adding symbols: file in wrong format"_ - looks like a showstopper for using that particular release of the library. If it's 10 years old, look for a newer release and make sure it's for the correct target platform. Fwiw, "trilinos-release-14-2-0" seems to be the latest. Compile it yourself from source if you can't find binaries for your platform. It's on github – Ted Lyngmo Jun 27 '23 at 19:42
  • Thanks so much Drew Dormann and Ted Lyngmo for giving me these directions. I will start working on it and let you know once I have any results! Thank you again for narrowing down the issue for me! – Zureas Jun 27 '23 at 20:04
  • By the way, the g++ version on my colleague's desktop is 5.4.0, but mine is 11.3.0. So yes, maybe it is due to the version mismatch between g++ and trilinos. – Zureas Jun 27 '23 at 20:07
  • Looks like it's probably due to my arm64 architecture (Macbook Air M2 chip). https://stackoverflow.com/a/63832669/16926455 – Zureas Jun 29 '23 at 23:09

1 Answers1

0

I think I found the root cause and just fixed it. It is because I used the libraries that are compiled on x86-64 (amd64) system, while my MacBook Air M2 is arm64 system. Their machine codes are different so my arm64 doesn't recognize the codes compiled by amd64 system.

> file libepetra.so.12
> libepetra.so.12: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=baf33e494c06b548b3c3fbfc159ead5d0424000c, not stripped

Compiling trilinos seems to be the only way to fix it, so I downloaded trilinos 13.0.0 and TriBITS to compile it. Below is my cmake command.

Test system

  • Macbook Air M2, 2022 (aarch64 architecture)
  • Ubuntu 22.04.2 LTS (jammy) based on UTM Virtual Machine

Instructions

  1. Download trilinos 13.0.0 from GitHub. Unpack it.
  2. Download TriBITS from GitHub. Unpack it.
  3. Put TriBITS inside the trilinos folder.
  4. Create a subfolder where you want to build trilinos. For example, <path to trilinos unpacked folder>/build
  5. Go to the build folder and execute the command cmake listed below.

non-MPI Trilinos

cmake \
-DCMAKE_C_COMPILER=/usr/bin/gcc \
-DCMAKE_CXX_COMPILER=/usr/bin/g++ \
-DCMAKE_Fortran_COMPILER=/usr/bin/gfortran \
-DTPL_ENABLE_MPI=OFF \
-DBUILD_SHARED_LIBS=ON \
-DTrilinos_ENABLE_AztecOO=ON \
-DTrilinos_ENABLE_Epetra=ON \
-DTrilinos_ENABLE_EpetraExt=ON \
-Dtrilinos_ENABLE_Gtest=ON \
-Dtrilinos_ENABLE_Kokkos=ON \
-Dtrilinos_ENABLE_Teuchos=ON \
-Dtrilinos_ENABLE_Triutils=ON \
-DTrilinos_ENABLE_FLOAT=ON \
-DCMAKE_INSTALL_PREFIX=/Home/Venus/Folders/NetBeans_Project/MyProject/lib/trilinos \
-DTrilinos_TRIBITS_DIR:STRING=/Home/Venus/Folders/Trilinos-source-13.0.0/TriBITS/tribits \
-DTrilinos_TRIBITS_PACKAGE_USE_TRIBITS_DIR=TRUE \
/Home/Venus/Folders/Trilinos-source-13.0.0

make install

MPI Trilinos

cmake \
-DCMAKE_C_COMPILER=/usr/bin/mpicc \
-DCMAKE_CXX_COMPILER=/usr/bin/mpicxx \
-DCMAKE_Fortran_COMPILER=/usr/bin/mpif77 \
-DTPL_ENABLE_MPI=ON \
-DBUILD_SHARED_LIBS=ON \
-DTrilinos_ENABLE_AztecOO=ON \
-DTrilinos_ENABLE_Epetra=ON \
-DTrilinos_ENABLE_EpetraExt=ON \
-Dtrilinos_ENABLE_Gtest=ON \
-Dtrilinos_ENABLE_Kokkos=ON \
-Dtrilinos_ENABLE_Teuchos=ON \
-Dtrilinos_ENABLE_Triutils=ON \
-DTrilinos_ENABLE_FLOAT=ON \
-DCMAKE_INSTALL_PREFIX=/Home/Venus/Folders/NetBeans_Project/MyProject/lib/trilinos-mpi \
-DTrilinos_TRIBITS_DIR:STRING=/Home/Venus/Folders/Trilinos-source-13.0.0/TriBITS/tribits \
-DTrilinos_TRIBITS_PACKAGE_USE_TRIBITS_DIR=TRUE \
/Home/Venus/Folders/Trilinos-source-13.0.0

make install

Now use file command to check the *.so files. Problem solved!

> file libepetra.so.13.0
> libepetra.so.13.0: ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=6593cc6bd0543c5823989303085c9472200fe144, not stripped
Zureas
  • 53
  • 5