OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World C program using printf. Compiles and runs fine on Kali Linux at home. When I upload the executable to the CentOS server via Filezilla and chmod and execute the file, I get a seg fault.

HostGator server CPU is AMD-Opteron-6378 running CentOS. I'm compiling using gcc on a Lenovo laptop using Kali Linux Live Boot and the gcc that comes with it. The compiling computer's processor is Intel Core i5-2450M, Little Endian, 64-bit, x86-64.

I compiled it using the regular old gcc helloworld.c -o helloworld. No warnings, no errors, runs fine. Same program seg faults on CentOS.

I ran the "file" command on the helloworld executable on the HostGator CentOS server and got this...

ERROR: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs) error reading (Invalid argument).

I'm a little confused on the "dynamically linked (uses shared libs)" part. What "linking" would there be? It's a Hello World program using printf.

I'm hoping this is just a problem with me not supplying the right compiler flags?

Recommended Answers

All 8 Replies

Okay, so I added the -static flag when compiling and the executable size went from about 6000 bytes to 800,000 bytes. I ran it again on the server. This time I got an "Illegal Instruction" error. Running "file" on the program yields...

ERROR: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linkederror reading (Invalid argument)

Note that "linkederror" being one word lower-case is not a typo. That's the output.

I googled priors on this and it appears you need to compile on the OS you want to target. I think you've seen a lot of apps are from repositories for each Linux OS version. So to target CentOS you need to compile with CentOS.

That out of the way, this is why many move to interpreted languages. Java, JS, PHP, etc.

Installed CentOS 7 Live Disk on a USB, rebooted to that, compiled on my laptop, uploaded, works!

So I'm good for C, but for some reason g++ does not exist in the CentOS repository. I could download/install gcc, but no joy on g++. Weird. You'd think if they had one, they'd have the other.

So I used google to see that gcc on centos question. It turns out you may have to compile gcc to get gcc.
https://www.vultr.com/docs/how-to-install-gcc-on-centos-6 for example. Of course you become an expert or descend into madness at that point.

Anyhow, glad my small contribution paid off above.

you may have to compile gcc to get gcc.

gcc I got no problem with a yum install gcc. I need g++ now.

Which I now have thanks to your link, though it may not have been the exact way you intended.

sudo yum install gcc gcc-c++

I had tried to "yum install" a whole bunch of one-offs of g++, but never thought of "gcc-c++". I tried "gcc-g++" a bunch of times, but never "gcc-c++" till I saw your link.

So, madness.

Glad it helped. My Linux work over the years has been more on those embedded versions like HardHat Linux. And right or wrong the embedded stuff was almost always straight up C.

You escaped the asylum.

Well I haven't escaped the asylum just yet. A few things aren't linking quite right. But I've escaped the asylum enough to mark this thread solved. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.