0

I am a newer of linux, I build a hello world as following command:

g++ -shared -fPIC helloworld.cpp -o hw

./hw causes

Segmentation fault (core dumped)

why?

g++ helloworld.cpp -o hw
./hw 

work well.

DavidPostill
  • 7,734
  • 9
  • 41
  • 60

1 Answers1

2

The first command builds a shared library instead of a executable file. Shared libraries are different from normal executable files. They (usually) cannot be executed directly, but can be used by other programs.

Community
  • 1
  • 1
user4098326
  • 1,712
  • 4
  • 16
  • 20