How To Write A Makefile With .c And .asm File

Hi,
I am working with Debian and gcc.

I have a single C file main.c, with some code in it.
For this trivial build, I am using the following Makefile:

Code:
SOURCES=main.c
CFLAGS=-c -w -gdwarf-4 -g3 -O0

LDFLAGS=
CC=

OBJECTS=$(SOURCES:.c=.o)
EXECUTABLE=myprogram

all: clean $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS)
	$(CC)gcc $(LDFLAGS) $(OBJECTS) -o $@

clean:
	rm -f $(EXECUTABLE) $(OBJECTS) $(MAKE)

.c.o:
	$(CC)gcc $(CFLAGS) $(LDFLAGS) $< -o $@

Now, in main.c, I want to use an assembly function, say myFunction which is implemented in the file function.asm.

My question is now: how do I build this? How do I modify the Makefile above to do this ?

Many thanks for your help!!!

PD.


Similar Content



.o: File Not Recognized: File Format Not Recognized When Compiling

Hello,

I am working on a board (sbc6000x with at91sam9261 micro, linux 2.6.24 to be precise) and having some fun making script i wanted to make real application.
The board is coming with a cross compilation toolchain. When trying to make a simple "hello world" executable to print on the terminal there is no problem.
I open my terminal, give the path of the compiler, cd into the folder where my .c file is and then i type :
Code:
arm-linux-gcc -o hello hello.c

Which create my executable "hello" and this one is working. But like i said, this program only played with the terminal.

The board is starting with a script calling another executable which use the lcd display, i have the source of this executable. My idea was to look at what was in the source of this application (lots of folders and files) in order to understand how it was working. I wanted to test the toolchain on the source (with the makefile) to see if i was able to generate an executable from a application with folderS/fileS but when i try to "make" it i have this error.

In my understanding this is an object file but aside from that i don't see why it would not works.

Thank you for your future answers !

What's Wrong With My /etc/apt/sources.list - Jessie.

Hi all,
This is my /etc/apt/sources.list of jessie, what's wrong as I am getting the following error output .

error :-

Code:
Err http://http.debian.net jesssie/main Sources
  404  Not Found [IP: 54.192.190.154 80]
Err http://http.debian.net jesssie/contrib Sources
  404  Not Found [IP: 54.192.190.154 80]
Err http://http.debian.net jesssie/non-free Sources                                                                                            
  404  Not Found [IP: 54.192.190.154 80]
Fetched 7,819 B in 25s (307 B/s)                                                                                                               
W: The repository 'http://http.debian.net jesssie Release' does not have a Release file. This is deprecated, please contact the owner of the repository.
W: Failed to fetch http://http.debian.net/debian/dists/jesssie/main/source/Sources  404  Not Found [IP: 54.192.190.154 80]

W: Failed to fetch http://http.debian.net/debian/dists/jesssie/contrib/source/Sources  404  Not Found [IP: 54.192.190.154 80]

W: Failed to fetch http://http.debian.net/debian/dists/jesssie/non-free/source/Sources  404  Not Found [IP: 54.192.190.154 80]

E: Some index files failed to download. They have been ignored, or old ones used instead.

This is my /etc/apt/sources.list :-

Code:
[$] cat /etc/apt/sources.list                                                                                                       [2:23:45]
#### testing  #########
deb http://http.debian.net/debian jessie main contrib non-free
deb-src http://http.debian.net/debian jesssie main contrib non-free

deb http://security.debian.org/ jessie/updates main contrib non-free
deb-src http://security.debian.org/ jessie/updates main contrib non-free

# testing-updates, previously known as 'volatile'
#deb http://http.debian.net/debian jessie-updates main contrib non-free
#deb-src http://http.debian.net/debian jessie-updates main contrib non-free

Now I am guessing one or more of the entries above are wrong, as probably all of testing-updates would probably come into play once jessie is released, right ?

This was generated via http://debgen.simplylinux.ch/ for lack of better places to generate sources.list from.

Update Manager Doesn't Work With Linux Mint 17.1 Mate

this is what I get after running "inxi -r"
Repos: Active apt sources in file: /etc/apt/sources.list.d/clipgrab-team-ppa-trusty.list
deb http://ppa.launchpad.net/clipgrab-team/ppa/ubuntu trusty main
deb-src http://ppa.launchpad.net/clipgrab-team/ppa/ubuntu trusty main
Active apt sources in file: /etc/apt/sources.list.d/ferramroberto-lffl-trusty.list
deb http://ppa.launchpad.net/ferramroberto/lffl/ubuntu trusty main
deb-src http://ppa.launchpad.net/ferramroberto/lffl/ubuntu trusty main
Active apt sources in file: /etc/apt/sources.list.d/getdeb.list
deb http://archive.getdeb.net/ubuntu trusty-getdeb apps
Active apt sources in file: /etc/apt/sources.list.d/gnome3-team-gnome3-trusty.list
deb http://ppa.launchpad.net/gnome3-team/gnome3/ubuntu trusty main
deb-src http://ppa.launchpad.net/gnome3-team/gnome3/ubuntu trusty main
Active apt sources in file: /etc/apt/sources.list.d/kalakris-okular-trusty.list
deb http://ppa.launchpad.net/kalakris/okular/ubuntu trusty main
deb-src http://ppa.launchpad.net/kalakris/okular/ubuntu trusty main
Active apt sources in file: /etc/apt/sources.list.d/kilian-f_lux-trusty.list
deb http://ppa.launchpad.net/kilian/f.lux/ubuntu trusty main
deb-src http://ppa.launchpad.net/kilian/f.lux/ubuntu trusty main
Active apt sources in file: /etc/apt/sources.list.d/libreoffice-ppa-trusty.list
deb http://ppa.launchpad.net/libreoffice/ppa/ubuntu trusty main
deb-src http://ppa.launchpad.net/libreoffice/ppa/ubuntu trusty main
Active apt sources in file: /etc/apt/sources.list.d/official-package-repositories.list
deb http://packages.linuxmint.com rebecca main upstream import
deb http://extra.linuxmint.com rebecca main
deb http://archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://archive.canonical.com/ubuntu/ trusty partner
Active apt sources in file: /etc/apt/sources.list.d/ricotz-testing-trusty.list
deb http://ppa.launchpad.net/ricotz/testing/ubuntu trusty main
deb-src http://ppa.launchpad.net/ricotz/testing/ubuntu trusty main

Thanks in advance, ScottG

What Does The "T" Mean When You List File Permissions W/ Ls -l

I have a directory w/ a file that I created using:
Code:
fd = open("file", O_CREAT);

The file turned out to be executable. When I did a 'ls -l' on the directory w'/ that file it has a "T" at the end of the permissions where the executable bit would be set for the "other" group.

How To Run Executable Files?

Can anyone teach this newbie how to open an executable file under Linux?? thanks!

Linux Dialog Executable

I was trying to write a simple menu using the "dialog" function only to find out that the version of linux i am running (I have previously worked on HP/Sun/ICL/AIX versions of unix)does not have the "dialog exe" and the one that someone has put on this box is not compatible.As follows:-

file /dir/dir/dir/dailog Retruns:-
dialog: ELF 32-bit MSB executable, SPARC, version 1 (SYSV), dynamically linked (uses shared libs), stripped

where as
file /usr/bin/diff
/usr/bin/diff: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), stripped

Where can I get the correct version of dialog.

uname -a gives :-
2.6.18-371.el5 #1 SMP Thu Sep 5 21:20:46 EDT 2013 i686 i686 i386 GNU/Linux

How To Share The Same Code Segment Between Two Processes Using Mmaps?

Hi Experts:

I'm new to Linux,recently i was confused with the words as below:

"To achieve sharing,the process A mmaps the executable file of process B into into the virtual address space of process A. As the Linux loader maps the executable files into the process when executing them,the two processes share the memory image of the mapped file"

questions:
1,What are the "executable files",are they ELF files?
2,How to do "mmaps"?if process A and process B share the same code segment, ,where is process A's own code segment?


Thank you in advance.

Executable Not Found From /usr/local/bin

Hi,

I installed ghostscript via yum package manager. Later I wanted a newer version of ghostscript and compiled it from source. "make install" placed the gs executable file under /usr/local/bin/gs. This works if I run the command with absolute path, but if try to run gs, the shell will output

"-bash: /usr/bin/gs: No such file or directory"

if I echo the path variable it will display

/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin

If i run whereis it will give me the correct path
gs: /usr/local/bin/gs

How do I make it work so that typing "gs" will run the executable file from the /usr/local/bin/gs?

(I am using Centos 6)

Thanks.

How Can I Run An Executable File On A Remote Linux Server Using Putty?

Hi, I'm trying to run an executable file on a remote server using Putty? I downloaded PuTTY and connected through the Putty Configuration window with the SSH connection type selected. Once I connected, the cmd window disappeared so I assume I'm connected. Now I want to run an executable file on the remote server.

How can I run an executable file on my remote Linux server using Putty?

Thanks for any help with this.

Unable To Install Driver

Hi, I am trying to install a smartcard reader driver onto my ubuntu machine. I am not able run the make file.

The output of makefile is as follows:
Code:
amit@ubuntu:~/Downloads/Linux Driver/rts_pstor$ sudo make
sed "s/RTSX_MK_TIME/`date +%y.%m.%d.%H.%M`/" timestamp.in > timestamp.h
cp -f ./define.release ./define.h
make -C /lib/modules/3.16.0-36-generic/build SUBDIRS=/home/amit/Downloads/Linux Driver/rts_pstor modules
make[1]: Entering directory `/usr/src/linux-headers-3.16.0-36-generic'
arch/x86/Makefile:136: CONFIG_X86_X32 enabled but no binutils support
Makefile:652: Cannot use CONFIG_CC_STACKPROTECTOR_REGULAR: -fstack-protector not supported by compiler
make[1]: *** No rule to make target `Driver/rts_pstor'.  Stop.
make[1]: Leaving directory `/usr/src/linux-headers-3.16.0-36-generic'
make: *** [default] Error 2
amit@ubuntu:~/Downloads/Linux Driver/rts_pstor$

The make file for this driver is as follows:

Code:
TARGET_MODULE := rts_pstor

EXTRA_CFLAGS := -Idrivers/scsi 

obj-m += $(TARGET_MODULE).o

$(TARGET_MODULE)-objs := rtsx.o rtsx_chip.o rtsx_transport.o rtsx_scsi.o rtsx_card.o \
			 general.o sd.o xd.o ms.o spi.o

default:
	sed "s/RTSX_MK_TIME/`date +%y.%m.%d.%H.%M`/" timestamp.in > timestamp.h
	cp -f ./define.release ./define.h
	make -C /lib/modules/$(shell uname -r)/build SUBDIRS=$(shell pwd) modules
debug:
	sed "s/RTSX_MK_TIME/`date +%y.%m.%d.%H.%M`/" timestamp.in > timestamp.h
	cp -f ./define.debug ./define.h
	make -C /lib/modules/$(shell uname -r)/build SUBDIRS=$(shell pwd) modules
install:
	cp $(TARGET_MODULE).ko /lib/modules/$(shell uname -r)/kernel/drivers/scsi -f
clean:
	rm -f *.o *.ko
	rm -f $(TARGET_MODULE).mod.c

Please let me know any of your comments.

Thanks,
Amit