Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » How to create a makefile in Assembly in Eclipse CDT, without C file?('makefile' in gas (.S file) in CDT, without using C (.c file))
How to create a makefile in Assembly in Eclipse CDT, without C file? [message #1834532] Wed, 11 November 2020 23:51 Go to next message
Tom KPB is currently offline Tom KPBFriend
Messages: 18
Registered: November 2020
Junior Member
Using Debian 10, x86-64 Architecture, and Eclipse CDT 2020-09.

Steps Followed:

(1) Create a Project

File > New > Project > C/C++ Project > C Project

Project name: HelloAsmMakefile

Project type: Makefile project > Empty Project, Linux GCC > Finish

(2) Create Source File

New > Source File Source File: hello.S
.text
.global main               # must be declared for linker (ld)

.func main
main:                      # tells linker entry point
    mov $len, %edx         # message length
    lea msg(%rip), %rsi    # message to write (RIP relative addressing)
    mov $1, %edi           # file descriptor (stdout)
    mov %edi, %eax         # system call number (sys_write)
    syscall

    ret

.data
msg: .ascii "Hello, world!\n"
len = . - msg              # length of the msg string

(3) Create a makefile

New > File > Filename: 'makefile' > Finish

Issue:

Most of the solutions are either using (1) C and AS files together, (2) 32-bit, (3) NASM, or (4) .asm file extension.

How do I create a makefile exclusively for gas (without C file), for CDT?

[Updated on: Wed, 11 November 2020 23:53]

Report message to a moderator

Re: How to create a makefile in Assembly in Eclipse CDT, without C file? [message #1834536 is a reply to message #1834532] Thu, 12 November 2020 04:12 Go to previous messageGo to next message
David VavraFriend
Messages: 1426
Registered: October 2012
Senior Member
You clearly don't understand what Make does.

A makefile consists of rules.
Each rule has three parts:

  1. target
  2. prerequisite(s)
  3. recipe

The target and prerequisites are files.
If any of the prerequisites are newer than the target
then Make executes the recipe in a shell to create or update the target.

The rules are examined in topological order.
Meaning Make determines which should be examined first.

The target and prerequisites can be generic.
For .S files a generic rule to assemble one to create an object file might be:
%.o: ../%.S
	@echo 'Building file: $<'
	@echo 'Invoking: GCC Assembler'
	as -g --gstabs -o "$@" "$<"
	@echo 'Finished building: $<'
	@echo ' '

In fact, that's the one generated by Eclipse for the ASMHello test I did for your previous question(s).
%.o is the target (an object file with the same name as the source)
%.S the prerequisite for the .o file (the source)
the rest is the recipe.

Eclipse will generate one for each source file type in the project.
And only if it is a Managed Build project.
If you don't want Eclipse generating rules for .c or .cpp files,
then don't put them in your project.

The makefiles generated by Eclipse are quite rudimentary.
Make can be confusing but you really need to knuckle down and learn it.

Here is the Introduction to Makefiles in the GNU Make manual:
https://www.gnu.org/software/make/manual/html_node/Introduction.html

Here's the entire manual:
https://www.gnu.org/software/make/manual/html_node/index.html

All of this is off-topic for this forum which is to address issues with CDT.
The forum is not meant to provide introductions, detailed instructions or discussions on using any particular external tool.

If you are truly interested, I suggest reading the manual
and perhaps Googling gnu make tutorial
or how to use gnu make

[Updated on: Thu, 12 November 2020 04:45]

Report message to a moderator

Re: How to create a makefile in Assembly in Eclipse CDT, without C file? [message #1834627 is a reply to message #1834532] Fri, 13 November 2020 17:36 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
Please find attached two makefiles: minimal is a minimum makefile to create a run file from hello.s. Please note the lower case s in file extension. An upper case S sends the translation via the gcc front-end if make default rules are used.

The other file (Makefile) is more complete, with customary build targets.
  • Attachment: minimal
    (Size: 0.08KB, Downloaded 114 times)
  • Attachment: Makefile
    (Size: 0.59KB, Downloaded 114 times)


--

Tauno Voipio
Re: How to create a makefile in Assembly in Eclipse CDT, without C file? [message #1834662 is a reply to message #1834627] Sat, 14 November 2020 21:09 Go to previous messageGo to next message
Tom KPB is currently offline Tom KPBFriend
Messages: 18
Registered: November 2020
Junior Member
Sir ( Tauno Voipio):

Thank you very much.

It solved my issue.

Once again, your factuality, clarity, and precision are the keys.

I deeply appreciate your help



[Updated on: Sat, 14 November 2020 21:19]

Report message to a moderator

Re: How to create a makefile in Assembly in Eclipse CDT, without C file? [message #1834679 is a reply to message #1834662] Sun, 15 November 2020 18:24 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
Thank you.

I took the Hello World example as a challenge and created the attached example code which is maybe the minimal version of the application.

The code created on a 32 bit system runs on both a 32 bit and a 64 bit system.
The file is a gzipped tar archive, to preserve the Linux mode bits.
  • Attachment: hello.tgz
    (Size: 1.32KB, Downloaded 103 times)


--

Tauno Voipio
Re: How to create a makefile in Assembly in Eclipse CDT, without C file? [message #1835082 is a reply to message #1834532] Tue, 24 November 2020 13:05 Go to previous messageGo to next message
Tauno Voipio is currently offline Tauno VoipioFriend
Messages: 742
Registered: August 2014
Senior Member
luna grover wrote on Tue, 24 November 2020 03:21
Most of the solutions are either using (1) C and AS files together, (2) 32-bit, (3) NASM, or (4) .asm file extension.


If you respond to my solutions:
(1) There is no C with embedded assembly,
(2) The solutions are for both 32 bit and 64 bit systems,
(3) There is no NASM, but GNU as instead,
(4) There is no .asm extension, but .S and .s


--

Tauno Voipio
Re: How to create a makefile in Assembly in Eclipse CDT, without C file? [message #1835688 is a reply to message #1835082] Thu, 10 December 2020 12:27 Go to previous message
Mark Smith is currently offline Mark SmithFriend
Messages: 82
Registered: September 2020
Member
Check this article
https://mcuoneclipse.com/2017/07/22/tutorial-makefile-projects-with-eclipse/
Previous Topic:How to include OpenGL + GLUT libraries in Eclipse in Mac OS X?
Next Topic:Advice on debugging C++ on Linux?
Goto Forum:
  


Current Time: Wed Oct 09 04:21:57 GMT 2024

Powered by FUDForum. Page generated in 0.04531 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top