Solved

linking objects

Posted on 2004-03-27
6
232 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
ID: 10697374
Add the objects to your link command in your project settings.
0
 
LVL 17

Accepted Solution

by:
rstaveley earned 45 total points
ID: 10697447
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
ID: 10956263
I would recommend accept rstaveley's answer.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

861 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