在大型C ++程序中插入C代码块 [英] Insert C code chunk in a big C++ program

查看:48
本文介绍了在大型C ++程序中插入C代码块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我不知道将这个问题发布到C或C ++

组是否更好,所以我很抱歉。


我的一般问题:


我有一个非常大的C ++程序(Main.cpp),可以在机器X上编译

使用编译器XA ++。


我还有一个函数,其源代码(function.c)在C(不是C ++)中

在机器X上编译使用编译器XBcc。


XA ++和XBcc是来自不同公司的编译器。


在机器上YI可以这样做:

1-使用编译器Y ++编译Main.cpp到目标文件Main.o

2-编译function.c到objetc文件function.o使用编译器

Ycc


编译器Y ++和Ycc来自同一家公司。 " Y"可能是GNU编译器的实例,所以我们有g ++和gcc。


3- Main.o将输入数据发送到function.o和function。 o返回

计算数据到Main.o.现在我以某种方式将Main.o链接到

function.o并创建Program_in_Y.exe。


我的一般问题是我是否可以执行相同的程序在机器X中。

也许同样的问题是,如果在同一台机器上使用不同的

编译器创建的对象可以以某种方式链接并创建一个

可执行文件或二进制文件。


谢谢。

Hi,

I don''t know if it is better to post this question to a C or C++
group, so my apologies.

My general question:

I have a very big C++ program (Main.cpp) which compiles on machine X
with compiler XA++.

I also have a function whose source code (function.c) in C (not C++)
compiles on machine X with compiler XBcc.

XA++ and XBcc are compilers from different companies.

On machine Y I can do:

1- compilation of Main.cpp to object file Main.o using compiler Y++
2- compilation of function.c to objetc file function.o using compiler
Ycc

Compilers Y++ and Ycc come from the same company. "Y" could be for
instance the GNU compiler so we would have g++ and gcc.

3- Main.o sends input data to function.o and function.o returns
calculated data to Main.o. Now I link in some way Main.o with
function.o and create Program_in_Y.exe.

My general question is if I can do the same procedure in machine X.
Perhaps the same question is if objects created with different
compilers on the same machine can link in some way and create an
executable or binary file.

Thanks.

推荐答案

5月19日,4日:02 am,horacius .... @ gmail.com写道:
On May 19, 4:02 am, horacius....@gmail.com wrote:




我不是知道将这个问题发布到C或C ++

组是否更好,所以我很抱歉。


我的一般问题:


我有一个非常大的C ++程序(Main.cpp),用编译器XA ++编译机器X




我也有一个函数,其源代码(function.c)在C(不是C ++)

在机器X上用编译器XBcc编译。


XA ++和XBcc是来自不同公司的编译器。


在机器上我可以这样做:


1-编译Main.cpp到目标文件Main.o使用编译器Y ++

2-编译function.c到objetc文件function.o使用编译器

Ycc


编译器Y ++和Ycc来自同一家公司。 " Y"可能是GNU编译器的实例,所以我们有g ++和gcc。


3- Main.o将输入数据发送到function.o和function。 o返回

计算数据到Main.o.现在我以某种方式将Main.o链接到

function.o并创建Program_in_Y.exe。


我的一般问题是我是否可以执行相同的程序在机器X中。

也许同样的问题是,如果在同一台机器上使用不同的

编译器创建的对象可以以某种方式链接并创建一个

可执行文件或二进制文件。


谢谢。
Hi,

I don''t know if it is better to post this question to a C or C++
group, so my apologies.

My general question:

I have a very big C++ program (Main.cpp) which compiles on machine X
with compiler XA++.

I also have a function whose source code (function.c) in C (not C++)
compiles on machine X with compiler XBcc.

XA++ and XBcc are compilers from different companies.

On machine Y I can do:

1- compilation of Main.cpp to object file Main.o using compiler Y++
2- compilation of function.c to objetc file function.o using compiler
Ycc

Compilers Y++ and Ycc come from the same company. "Y" could be for
instance the GNU compiler so we would have g++ and gcc.

3- Main.o sends input data to function.o and function.o returns
calculated data to Main.o. Now I link in some way Main.o with
function.o and create Program_in_Y.exe.

My general question is if I can do the same procedure in machine X.
Perhaps the same question is if objects created with different
compilers on the same machine can link in some way and create an
executable or binary file.

Thanks.



5月19日下午1点40分,popy ... @ gmail.com写道:
On May 19, 1:40 pm, popy...@gmail.com wrote:

5月19日凌晨4:02,horacius .... @ gmail.com写道:
On May 19, 4:02 am, horacius....@gmail.com wrote:


Hi,


我不知道将这个问题发布到C或C ++

组是否更好,所以我道歉。
I don''t know if it is better to post this question to a C or C++
group, so my apologies.


我的一般问题:
My general question:


我有一个非常大的C ++程序(Main.cpp),使用编译器XA ++在机器X上编译

I have a very big C++ program (Main.cpp) which compiles on machine X
with compiler XA++.


我还有一个函数,其源代码(function.c)用C(不是C ++)

在机器上编译X与编译器XBcc。
I also have a function whose source code (function.c) in C (not C++)
compiles on machine X with compiler XBcc.


XA ++和XBcc是来自不同公司的编译器。
XA++ and XBcc are compilers from different companies.



........

........


3- Main.o将输入数据发送到function.o并且function.o返回

计算数据到Main.o.现在我以某种方式将Main.o链接到

function.o并创建Program_in_Y.exe。
3- Main.o sends input data to function.o and function.o returns
calculated data to Main.o. Now I link in some way Main.o with
function.o and create Program_in_Y.exe.


我的一般问题是我是否可以在机器X中执行相同的程序。

也许同样的问题是if对象在同一台机器上用不同的
编译器创建可以以某种方式链接并创建一个

可执行文件或二进制文件。
My general question is if I can do the same procedure in machine X.
Perhaps the same question is if objects created with different
compilers on the same machine can link in some way and create an
executable or binary file.



从技术上讲,如果两个编译器都生成相同的对象格式,那么

可以链接,只剩下问题就是调用约定。 />
你可以看看你是否可以指定接口的调用约定

函数explicitelly。另一个问题是,好像编译器没有; t
根本没有兼容的调用约定。

然后你运气不好,因为那时你必须在
汇编程序将转发参数

和函数之间的结果。

当然你必须确保参数的布局

和结果匹配。例如,对于一个编译器,long double可以是
64 bit和其他80位,更不用说结构了。

总而言之。如果你没有汇编程序的经验,那么用XA ++编译Main.cpp和

function.c(可能的更正)会更容易。


问候,Branimir。

Technically if both compilers produce same object format that
can link, only problem that remains is calling convention.
You can see if you can specify calling convention of interfacing
functions explicitelly. Another problem is, as if compilers don;t
have compatible calling conventions at all.
Then you are out of luck, as then you have to write thunks in
assembler that will forward parameters
and result between functions.
And of course you have to make sure that layout for parameters
and results match. eg long double for one compiler can be
64 bit and for other 80 bit, not to mention structs.
All in all tough luck. If you are not experienced in assembler
programming then it is easier to just compile both Main.cpp and
function.c (with possible corrections) with XA++.

Greetings, Branimir.


On 19 Mai,18:02,horacius .... @ gmail.com写道:
On 19 Mai, 18:02, horacius....@gmail.com wrote:




我不知道将这个问题发布到C或C ++是否更好

组,所以我很抱歉。


我的一般问题:


我有一个非常大的C ++程序( Main.cpp)用编译器XA ++编译机器X




我还有一个函数,其源代码(function.c)在C中(不是C ++)

使用编译器XBcc在机器X上编译。

XA ++和XBcc是来自不同公司的编译器。


在机器上YI可以这样做:


1-使用编译器Y ++编译Main.cpp到目标文件Main.o

2-编译f unction.c到objetc文件function.o使用编译器

Ycc


编译器Y ++和Ycc来自同一家公司。 " Y"可能是GNU编译器的实例,所以我们有g ++和gcc。


3- Main.o将输入数据发送到function.o和function。 o返回

计算数据到Main.o.现在我以某种方式将Main.o链接到

function.o并创建Program_in_Y.exe。


我的一般问题是我是否可以执行相同的程序在机器X中。

也许同样的问题是,如果在同一台机器上使用不同的

编译器创建的对象可以以某种方式链接并创建一个

可执行文件或二进制文件。


谢谢。
Hi,

I don''t know if it is better to post this question to a C or C++
group, so my apologies.

My general question:

I have a very big C++ program (Main.cpp) which compiles on machine X
with compiler XA++.

I also have a function whose source code (function.c) in C (not C++)
compiles on machine X with compiler XBcc.

XA++ and XBcc are compilers from different companies.

On machine Y I can do:

1- compilation of Main.cpp to object file Main.o using compiler Y++
2- compilation of function.c to objetc file function.o using compiler
Ycc

Compilers Y++ and Ycc come from the same company. "Y" could be for
instance the GNU compiler so we would have g++ and gcc.

3- Main.o sends input data to function.o and function.o returns
calculated data to Main.o. Now I link in some way Main.o with
function.o and create Program_in_Y.exe.

My general question is if I can do the same procedure in machine X.
Perhaps the same question is if objects created with different
compilers on the same machine can link in some way and create an
executable or binary file.

Thanks.



啊,这是一个很好的家庭作业问题!


通常每个平台都有一个ABI,它告诉你如何传递参数

到一个函数等。

如果编译器A服从这个ABI并且编译器''B''你没有

a问题,否则

它可能有用(如果运行时函数也兼容)。你

也可能有不同的

标识符名称,如前面的下划线。


欲了解更多信息,请使用书籍清单中的参考文献你的

老师给了你。

Ah, a good homework question!

Normally every platform has a ABI which tells how to pass parameters
to a function etc.
If the compiler A obeys to this ABI and compiler ''B'' does not you have
a problem otherwise
it might work (if the runtime functions are also compatible). You
might also have different
identifier names like preceding underscores.

For more information please use the references in the books list your
teacher gave you.


这篇关于在大型C ++程序中插入C代码块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆