Code Blocks IDE and Linking ASM

Discussion about everything. New games, 3d math, development tips...
Post Reply
Alpha Omega
Posts: 288
Joined: Wed Oct 29, 2008 12:07 pm

Code Blocks IDE and Linking ASM

Post by Alpha Omega »

Hello everyone,

I am curious if there is a way of linking compiled object files inside the Code Blocks IDE? For example, I have written some low level I/O functions in assembler and have compiled it with NASM assembler. I have the win32 .obj (I am compiling on windows), is there a way to link this within code blocks so when I build the project I can reference these functions in my main() program?

I know I can call ld.exe main.o file1.o file2.0 and link it, but I want code blocks to do that for me?

Any C::B vets around? It would be much appreciated. :)

(OOPS I posted in wrong thread, I thought this was Off Topic :((( ) Sorry!
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Code Blocks IDE and Linking ASM

Post by Mel »

(will be moved soon, i guess...)

I'd suggest that you learnt how to write functions in assembler code, that way the compiler would make an OBJ with the binary code, and the proper interface. and would be less complex to link with other programs.
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Alpha Omega
Posts: 288
Joined: Wed Oct 29, 2008 12:07 pm

Re: Code Blocks IDE and Linking ASM

Post by Alpha Omega »

Mel,

I am a little confused on what your advice is. Maybe I can clarify. I have my .asm files, I run nasm assembler on them to get .obj files. Now I could make these .obj files into a .lib and then link with C::B which should work but I dont know how to make a .lib!

I have done this before inside code blocks and it worked but I am having trouble with the linker settings inside C::B.

Do you know how to make a .lib with a bunch of .obj files :)?

Thanks!
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Code Blocks IDE and Linking ASM

Post by Mel »

What i meant was that you did something like in here: http://cboard.cprogramming.com/cplusplu ... mingw.html and compiled your project as you'd normally do. The only way i can think of now is using the "ar" command directly on the Windows console, though i guess you are looking for something more elaborate.

You can link .OBJs directly too into an application the same as if they were libs. though i understand that a library is more convenient. Can't you create a project whose output is a library file and the files are the assembly sources?
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
Alpha Omega
Posts: 288
Joined: Wed Oct 29, 2008 12:07 pm

Re: Code Blocks IDE and Linking ASM

Post by Alpha Omega »

I switch to VS 2010 C++ and I just add the .obj files in the linker section and it works! I forgot extern "C" though lol. I think my C::B setup at work is not setup right because there was already a GCC compiler on this machine and although I can get a simple hello world to build I can not build the sample. I will try at home to confirm if its the setup for C::B.
Mel
Competition winner
Posts: 2292
Joined: Wed May 07, 2008 11:40 am
Location: Granada, Spain

Re: Code Blocks IDE and Linking ASM

Post by Mel »

You should be able to do it with any compiler :)
"There is nothing truly useless, it always serves as a bad example". Arthur A. Schmitt
CuteAlien
Admin
Posts: 9651
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Code Blocks IDE and Linking ASM

Post by CuteAlien »

You know that C::B also has forums so you can ask the C::B developers directly? :-)
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
DJLinux
Posts: 19
Joined: Fri Dec 02, 2011 4:39 am
Location: germany
Contact:

Re: Code Blocks IDE and Linking ASM

Post by DJLinux »

In C::B you can use inline assembler in *.c or *.cpp files but in GNU syntax not Intel.
Or put your whole assembler stuff in seperate *.s and *.S files (you can use Intel syntax in this case too).
Note: *.s *.S are case sensitive under windows too !!!
One of them are preprocessed by the C++ preprocessor the other not.
(I can't remember witch of them are ignored by the C++ preprocessor)
Add *.s or *.S files to your C++ C::B project the rest is done by the IDE and gcc.

DJ.
(Sorry about my bad English)
Post Reply