Jump to content

sooo, I have C file I need to compile as executable on Linux (using Ubuntu 16), but even if I try with gcc, I always end up with a shared library. I can't understand why this happens, as the file comes with the already compiled executable (not a shared library) and I didn't change anything but a few lines of code (some keyboard scan codes, nothing truly important).

 

Some code extracts (file is quite long, so I'll just cut some unimportant parts):

 

#include <pthread.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <fcntl.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
  
#define BUF_LEN 512
 
struct options {
  	const char		*opt;
  	unsigned char	val;
};

[some static structs here]

[some functions here, int and void]

int main(int argc, const char *argv[])
{
  	[stuff here]
  	return 0;
}

 

Any ideas?

Computer Case: NZXT S340 || CPU: AMD Ryzen 5 1600 || Cooler: CM Hyper212 Evo || MoBo: MSI B350 Mortar || RAM Vengeance LPX 2x8GB 3200MHz || PSU: Corsair CX600 || SSD: HyperX Fury 120GB & 240GB || HDD: WD Blue 1TB + 1TB 2.5'' backup drive || GPU: Sapphire Nitro+ RX 580 4GB

Laptop 1 HP x360 13-u113nl

Laptop Lenovo z50-75 with AMD FX-7500 || OS: Windows 10 / Ubuntu 17.04

DSLR Nikon D5300 w/ 18-105mm lens

Link to comment
https://linustechtips.com/topic/744604-c-compiling-problem/
Share on other sites

Link to post
Share on other sites

10 minutes ago, Seuntjie said:

Can you post the command you're using to compile?

gcc filename.c -o filename

 

Computer Case: NZXT S340 || CPU: AMD Ryzen 5 1600 || Cooler: CM Hyper212 Evo || MoBo: MSI B350 Mortar || RAM Vengeance LPX 2x8GB 3200MHz || PSU: Corsair CX600 || SSD: HyperX Fury 120GB & 240GB || HDD: WD Blue 1TB + 1TB 2.5'' backup drive || GPU: Sapphire Nitro+ RX 580 4GB

Laptop 1 HP x360 13-u113nl

Laptop Lenovo z50-75 with AMD FX-7500 || OS: Windows 10 / Ubuntu 17.04

DSLR Nikon D5300 w/ 18-105mm lens

Link to comment
https://linustechtips.com/topic/744604-c-compiling-problem/#findComment-9433714
Share on other sites

Link to post
Share on other sites

2 minutes ago, Unimportant said:

You should add the command line option:

-pthread

do you mean doing this?

gcc filename.c -pthread -o filename

I'm still getting a shared library

 

7 minutes ago, Unimportant said:

I suppose you're getting a linker error about pthread and because the link fails, you get stuck with the object file only ?

gcc doesn't output any kind of error

Computer Case: NZXT S340 || CPU: AMD Ryzen 5 1600 || Cooler: CM Hyper212 Evo || MoBo: MSI B350 Mortar || RAM Vengeance LPX 2x8GB 3200MHz || PSU: Corsair CX600 || SSD: HyperX Fury 120GB & 240GB || HDD: WD Blue 1TB + 1TB 2.5'' backup drive || GPU: Sapphire Nitro+ RX 580 4GB

Laptop 1 HP x360 13-u113nl

Laptop Lenovo z50-75 with AMD FX-7500 || OS: Windows 10 / Ubuntu 17.04

DSLR Nikon D5300 w/ 18-105mm lens

Link to comment
https://linustechtips.com/topic/744604-c-compiling-problem/#findComment-9434042
Share on other sites

Link to post
Share on other sites

25 minutes ago, Cryosec said:

do you mean doing this?


gcc filename.c -pthread -o filename

I'm still getting a shared library

 

gcc doesn't output any kind of error

I suppose you're trying to compile this? https://github.com/dweinstein/hid/blob/master/jni/hid-gadget-test.c

 

Compiles fine for me with the command line option you gave. What makes you think it's outputting a shared lib? Has it got a .so extention?

Link to comment
https://linustechtips.com/topic/744604-c-compiling-problem/#findComment-9434157
Share on other sites

Link to post
Share on other sites

33 minutes ago, Unimportant said:

I suppose you're trying to compile this? https://github.com/dweinstein/hid/blob/master/jni/hid-gadget-test.c

 

Compiles fine for me with the command line option you gave. What makes you think it's outputting a shared lib? Has it got a .so extention?

yup, that's the file. it doesn't have an extention, but file properties say it's a shared lib and it doesn't execute when called (even if set as executable with chmod)

Computer Case: NZXT S340 || CPU: AMD Ryzen 5 1600 || Cooler: CM Hyper212 Evo || MoBo: MSI B350 Mortar || RAM Vengeance LPX 2x8GB 3200MHz || PSU: Corsair CX600 || SSD: HyperX Fury 120GB & 240GB || HDD: WD Blue 1TB + 1TB 2.5'' backup drive || GPU: Sapphire Nitro+ RX 580 4GB

Laptop 1 HP x360 13-u113nl

Laptop Lenovo z50-75 with AMD FX-7500 || OS: Windows 10 / Ubuntu 17.04

DSLR Nikon D5300 w/ 18-105mm lens

Link to comment
https://linustechtips.com/topic/744604-c-compiling-problem/#findComment-9434304
Share on other sites

Link to post
Share on other sites

6 minutes ago, Cryosec said:

yup, that's the file. it doesn't have an extention, but file properties say it's a shared lib and it doesn't execute when called (even if set as executable with chmod)

What does file have to say about it ? (execute "file filename" in a terminal, in the directory where the file is).

 

In the off chance you do not know, you have to start console applications from the terminal in many linux distro's, often they don't work when executed from a gui explorer.

execute with  ./filename

Link to comment
https://linustechtips.com/topic/744604-c-compiling-problem/#findComment-9434337
Share on other sites

Link to post
Share on other sites

12 minutes ago, Unimportant said:

What does file have to say about it ? (execute "file filename" in a terminal, in the directory where the file is).

 

In the off chance you do not know, you have to start console applications from the terminal in many linux distro's, often they don't work when executed from a gui explorer.

execute with  ./filename

Don't worry, I know my way around Linux :D 

 

Anyway, my version of hid-gadget-test is different, as it's used inside a Pi Zero for emulating keyboard strokes (a low cost USB Rubber Ducky).

 

When I execute the file from Ubuntu, it just shows normal "help" output (weird, it didn't do this a week ago), as there are no options given.

But when I copy the file to the Pi Zero microSD, it won't execute (I can tell this because it should be typing commands, as with the original compiled file), so I suspected it was for this shared lib stuff

Computer Case: NZXT S340 || CPU: AMD Ryzen 5 1600 || Cooler: CM Hyper212 Evo || MoBo: MSI B350 Mortar || RAM Vengeance LPX 2x8GB 3200MHz || PSU: Corsair CX600 || SSD: HyperX Fury 120GB & 240GB || HDD: WD Blue 1TB + 1TB 2.5'' backup drive || GPU: Sapphire Nitro+ RX 580 4GB

Laptop 1 HP x360 13-u113nl

Laptop Lenovo z50-75 with AMD FX-7500 || OS: Windows 10 / Ubuntu 17.04

DSLR Nikon D5300 w/ 18-105mm lens

Link to comment
https://linustechtips.com/topic/744604-c-compiling-problem/#findComment-9434443
Share on other sites

Link to post
Share on other sites

12 minutes ago, Cryosec said:

Don't worry, I know my way around Linux :D 

 

Anyway, my version of hid-gadget-test is different, as it's used inside a Pi Zero for emulating keyboard strokes (a low cost USB Rubber Ducky).

 

When I execute the file from Ubuntu, it just shows normal "help" output (weird, it didn't do this a week ago), as there are no options given.

But when I copy the file to the Pi Zero microSD, it won't execute (I can tell this because it should be typing commands, as with the original compiled file), so I suspected it was for this shared lib stuff

So, if I understand correctly, you're compiling on PC and then copying the executable to the Pi Zero?

gcc on PC will create a x86 executable for PC, the Pi's CPU is a ARM.

 

You need to install and compile with gcc on the Pi zero to create a executable for the Pi.

(Or possibly a cross compiler that runs on PC but creates a executable for the Pi, if such a thing exists)

Link to comment
https://linustechtips.com/topic/744604-c-compiling-problem/#findComment-9434506
Share on other sites

Link to post
Share on other sites

Just now, Unimportant said:

So, if I understand correctly, you're compiling on PC and then copying the executable to the Pi Zero?

gcc on PC will create a x86 executable for PC, the Pi's CPU is a ARM.

 

You need to install and compile with gcc on the Pi zero to create a executable for the Pi.

(Or possibly a cross compiler that runs on PC but creates a executable for the Pi, if such a thing exists)

I realized that moments ago ahah

but still, why is it showing as a shared lib even if compiled for PC?

Computer Case: NZXT S340 || CPU: AMD Ryzen 5 1600 || Cooler: CM Hyper212 Evo || MoBo: MSI B350 Mortar || RAM Vengeance LPX 2x8GB 3200MHz || PSU: Corsair CX600 || SSD: HyperX Fury 120GB & 240GB || HDD: WD Blue 1TB + 1TB 2.5'' backup drive || GPU: Sapphire Nitro+ RX 580 4GB

Laptop 1 HP x360 13-u113nl

Laptop Lenovo z50-75 with AMD FX-7500 || OS: Windows 10 / Ubuntu 17.04

DSLR Nikon D5300 w/ 18-105mm lens

Link to comment
https://linustechtips.com/topic/744604-c-compiling-problem/#findComment-9434527
Share on other sites

Link to post
Share on other sites

3 minutes ago, Cryosec said:

I realized that moments ago ahah

but still, why is it showing as a shared lib even if compiled for PC?

Is it showing up as a shared lib on the Pi or on PC ?

If on the Pi, it could simply be the file explorer on the Pi not knowing what to make of it.

If on PC, that would be rather weird, but you should always use the file command to be sure anyway.

Link to comment
https://linustechtips.com/topic/744604-c-compiling-problem/#findComment-9434562
Share on other sites

Link to post
Share on other sites

20 minutes ago, Unimportant said:

Is it showing up as a shared lib on the Pi or on PC ?

If on the Pi, it could simply be the file explorer on the Pi not knowing what to make of it.

If on PC, that would be rather weird, but you should always use the file command to be sure anyway.

on PC, hence this thread. I tested this on Ubuntu and Kali, both showing it as a shared lib

 

Also, I just compiled the file on a Pi 2 with Kali on it, moved it on the PiZero and still it doesn't run (checking the file properties on Ubuntu shows it as a shared lib again:

 

hid-gadget-test: ELF 32-bit LSB shared object, ARM, EABIS version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNUL/Linux 3.2.0, BuildUI[sha1]=blablabla, not stripped

(sorry for the blablabla but I didn't want to copy manually all the hash, as I'm typing from another device)

Computer Case: NZXT S340 || CPU: AMD Ryzen 5 1600 || Cooler: CM Hyper212 Evo || MoBo: MSI B350 Mortar || RAM Vengeance LPX 2x8GB 3200MHz || PSU: Corsair CX600 || SSD: HyperX Fury 120GB & 240GB || HDD: WD Blue 1TB + 1TB 2.5'' backup drive || GPU: Sapphire Nitro+ RX 580 4GB

Laptop 1 HP x360 13-u113nl

Laptop Lenovo z50-75 with AMD FX-7500 || OS: Windows 10 / Ubuntu 17.04

DSLR Nikon D5300 w/ 18-105mm lens

Link to comment
https://linustechtips.com/topic/744604-c-compiling-problem/#findComment-9434664
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×