I'm getting a segmentation fault int the executable when I compile my c++ program from in a different folder

StackOverflow https://stackoverflow.com/questions/20635136

Frage

I'm working with the ARIA robotics library. I have the library installed in /usr/local/Aria So far I've put all the new code I write in a folder in the /usr/local/Aria/examples folder and compiled it from the top level /usr/local/Aria library using g++. This works fine and I get a working executable. But I wanted to try and move my project to another folder. Call this folder ~/Documents/workspace/code

After a lot of trial and error I found that the only way to get a compilation without the compiler showing any errors was to cd into the /usr/local/Aria directory and run

g++ -g -Wall -D_REENTRANT -fPIC -Iinclude -I~/Documents/workspace/robotcode/include ~/Documents/workspace/robotcode/robotCode.cpp -o ~/Documents/workspace/robotcode/robotCode -Llib -lAria -ldl -lrt

This code compiles the code fine but when i run the executable generated the program shows

Aria: Received signal 'SIGSEGV'. Exiting

So here's what I'm confused about: I compiled the exact same code in the two directories. The only difference between the two compilations was the different working directory. So I concluded that the segfault was because of the different directory.

Does anyone have any idea why this could happen? I can still work in the /usr/local/Aria directory but it would be convenient if I could put all my project files in a separate folder.

I'm working in Ubuntu 12.04

War es hilfreich?

Lösung

Run ldd your_executable. It will show you the dependencies of your executable. I suspect that either libraries are linked relatively to your executable and you move it around without moving libraries, or is linked absolutely and you move libraries together with executable.

So just run ldd your_executable from both locations and compare results to find out.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top