anderkve / FYS3150

https://anderkve.github.io/FYS3150
26 stars 14 forks source link

Issue with running executable file #8

Closed SebastianRT1 closed 3 years ago

SebastianRT1 commented 3 years ago

Does anyone know how to fix an issue with running an executable file giving this error message:

dyld: Library not loaded: /usr/local/opt/libevent/lib/libevent_core-2.1.7.dylib Referenced from: /usr/local/opt/open-mpi/lib/libmpi_usempif08.40.dylib Reason: image not found Abort trap: 6

I have checked each library that everything should be there, but can't find the issue.

anderkve commented 3 years ago

Hmm, are you trying do implement some sort of MPI parallellisation? Otherwise I cannot see why it should be trying to load libmpi... (You might be seeing something like this issue, https://github.com/firedrakeproject/firedrake/issues/1452 , where there is some mix of tools being used in the compilation of the code.)

Could you send the exact command you use to compile and link your code?

SebastianRT1 commented 3 years ago

Hmm, are you trying do implement some sort of MPI parallellisation? Otherwise I cannot see why it should be trying to load libmpi... (You might be seeing something like this issue, firedrakeproject/firedrake#1452 , where there is some mix of tools being used in the compilation of the code.)

Could you send the exact command you use to compile and link your code?

I use: g++ -c -std=c++11 main.cpp g++ main.o - o main.exe -larmadillo ./main.exe 100

and it is on the last them I get the error message, but my lab-partner does not.

evenmn commented 3 years ago

Does this only happen when you run your code with Armadillo? And do you have one of the new MacBooks with M1 chip?

I got some similar error messages after I compiled Armadillo through Rosetta2 on my mac, but I don't know if it's related.

anderkve commented 3 years ago

Hmm, looks like some sort of mixup of compilers and libraries. Some questions:

If you are running the Clang compiler, one option is to try to install the GNU compiler via homebrew, i.e. brew install gcc. (The installation might be quite large -- I'm not sure.)

Then you should have a new g++ compiler available, named something like g++-10 (or some other number). If you use g++-10 rather than just g++ in your commands you are then using the GNU compiler rather than the Clang one, which often can solve issues like this on Mac.

EDIT: ah, just noticed the answer from @evenmn :)

SebastianRT1 commented 3 years ago

I have a fairly old MacBook from 2013.

I know that armadillo is a problem on my computer, and that the code I try to run now use armadillo. However I have tried to run older versions of our code that still use armadillo and it hasn't been a problem before now. I tried to run other more simple codes and they run perfectly fine. So I would assume that armadillo is the problem.

It might also be a compiler issue, as I for previous projects (at the other university I went to) have used both GNU and Clang. I checked now, and I have to use g++-11, and then it tells me that I have no file or directory called armadillo.

I have gone through each step of downloading armadillo, and since this problem occurred I have tried to both reinstall it and to update it. So I don't know why my computer can't find it...

evenmn commented 3 years ago

This sounds like a path problem. You have Armadillo, but your compiler does not look for Armadillo at the right place. You can add the path to the armadillo header file manually. First, find the location of the file. If you installed armadillo with Homebrew, try: brew --prefix armadillo When I run the command, I get /opt/homebrew/opt/armadillo. The path to the header file is then /opt/homebrew/opt/armadillo/include. Then link Armadillo manually: g++ -std=c++11 main.cpp -o main.out -I /opt/homebrew/opt/armadillo/include -DARMA_USE_LAPACK -DARMA_USE_BLAS -DARMA_DONT_USE_WRAPPER -llapack -lblas

Sorry for the ugly command, but hopefully it will help (at least it works for me).

SebastianRT1 commented 3 years ago

That helped me for that step, but when I then try to create an executable file using any combination I can think of I get: ld: unexpected token: !tapi-tbd-v3 file '/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/lib/libSystem.tbd' for architecture x86_64 collect2: error: ld returned 1 exit status

SebastianRT1 commented 3 years ago

We can finish this project without me having to compile and run the main file, if it is easier to look at it in one of the lab-sessions (most important is to get it fixed before we get into the next project) but it will give my partner extra work, so if you have any ideas that would be appreciated.

evenmn commented 3 years ago

The magic command about should both compile and link, and thus give you an executable main.out. Do you not get this executable?

anderkve commented 3 years ago

Just to avoid confusion: in the lectures I've named executables with .exe ending, but this is just a convention -- you can give it any name you want, e.g main.out. So as @evenmn says, if the command g++ -std=c++11 main.cpp -o main.out -I /opt/homebrew/opt/armadillo/include -DARMA_USE_LAPACK -DARMA_USE_BLAS -DARMA_DONT_USE_WRAPPER -llapack -lblas (or with g++-11 instead of g++) completed successfully, you should have an executable called main.out that you can run like ./main.out.

anderkve commented 3 years ago

Having said that, system-dependent linking errors like are typically much easier to solve in person (and even then they can be tricky...), so it may be most useful for you to focus on finalizing the project now, and then try to solve this problem before we start on Project 2 on Thursday, or in a lab session on Thursday. :)

SebastianRT1 commented 3 years ago

I will probably do that, because when I try to do ./main.out I get "permission denied"

anderkve commented 3 years ago

Huh, that's a strange error. But one last thing to try now would be to try to change the file permissions, to give yourself executable permission. Try chmod u+x main.out, or if you get a "permission denied" error from that command too, try sudo chmod u+x main.out (you will be prompted for your password). Then try running ./main.out again.

(The chmod command is explained on the terminal tutorial pages: https://anderkve.github.io/FYS3150/book/using_the_terminal/basics.html)

SebastianRT1 commented 3 years ago

That fixed the final bit, now everything works, thank you to the both of you!

anderkve commented 3 years ago

Happy to hear that! Good luck with the rest of the work :)