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.
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
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)
g++ (Ubuntu 11.3.0-1ubuntu1~22.04.1) 11.3.0 (g++ on my Linux)
What I am still trying to check:
Could someone please help me? I have been struggling with it for several days. I would truly appreciate it! Thank you.
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.
<path to trilinos unpacked folder>/build
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
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