Solved

linking objects

Posted on 2004-03-27
6
227 Views
Last Modified: 2010-04-01
how can i link assembly objects with object that compiled on turbo c++
0
Comment
Question by:akayed
6 Comments
 
LVL 30

Expert Comment

by:Axter
Comment Utility
Add the objects to your link command in your project settings.
0
 
LVL 17

Accepted Solution

by:
rstaveley earned 45 total points
Comment Utility
Let's assume you have a void function which takes no parameters, which prints "Hello, world" in C tradition. The function is, however, written in assmembler. Let's call the function Hello().

Here's a possible TASM/MASM source.

hello.asm:
--------8<--------
.MODEL small,C
.DATA
    message DB "Hello, world$"
.CODE
PUBLIC Hello
Hello PROC NEAR
    MOV AH,9  
    MOV DX,OFFSET message
    INT 21h
    RET
Hello ENDP
END
--------8<--------

The memory model matches the memory model used in the C/C++ compilation. The .MODEL is supplied the C specifier to prefix public symbols with a leading underscore just like C does. That way the Hello PROC is seen by the linker as _Hello. .CODE and .DATA names segments in the same way that they are named by C programs.

In your C++ module you should prototype the Hello function with extern "C" to prevent C++ name-mangling.

main.cpp:
--------8<--------
extern "C" void Hello(void);

int main()
{
        Hello();
        return 0;
}
--------8<--------

You can use tcc to compile main.cpp and ink it with the start-up code, libraries and hello.obj thus:

        tcc main.cpp hello.obj

Alternatively, you can add hello.obj to the link in the IDE.
0
 
LVL 3

Expert Comment

by:CoolBreeze
Comment Utility
I would recommend accept rstaveley's answer.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now