Solved

linking objects

Posted on 2004-03-27
6
230 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

803 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