我不能同意你的具体申请。我可以说的是:C++库可以调用C库,但是C++支持重载。因此,它可以支持:int pOw(int,int);双PoW(double,double);在C编译的库中,应该用多次定义的符号来获得错误,链接器不知道该选择哪一个(或者它总是选择第一个定义,然后你会得到奇怪的行为)。在一个C++编译的库中,名字将被修改,C++编译器/链接器将知道根据参数使用哪一个。在大多数情况下,在嵌入式系统中,当你在混合C++C++时,你希望使用C库,除非你需要像上面提到的那样重载。这样一来,你的C代码和C++代码都将使用相同的符号,并且由于名称的篡改和使用Flash空间,你不会有重复的目标代码。(注:一些编译器/链接器将找到重复的对象代码,并将所有的东西指向一个副本,并删除其他副本。我不知道XC32是否这样做。从你所写的看来,你将需要C和C++版本的代码,因为该库使用C++数学函数。
以上来自于百度翻译
以下为原文
I can't say for your specific application. What I can say is:
C++ libraries can call C libraries.
But C++ supports overloading. So it can support for example:
- int pow(int, int);
- double pow(double, double);
In a C compiled library you should get errors with symbols defined multiple times, and the linker wouldn't know which to choose (or it'll always choose the first one defined and then you'll get strange behavior). In a C++ compiled library the names will be mangled and the C++ compiler/linker will know which one to use based on the parameters.
In most cases on an embedded system when you're mixing C & C++ you want to use the C libraries unless you need something like overloading as I stated above. This way both your C code and your C++ code will use the same symbol and you won't have object code duplicated because of the name mangling and using up flash space.
(One note: some compilers/linkers will find the duplicated object code and point everything to one copy and eliminate the others. I don't know if XC32 does this).
From what you wrote it looks like you will need both the C and C++ versions of the code because that library uses the C++ math functions.
我不能同意你的具体申请。我可以说的是:C++库可以调用C库,但是C++支持重载。因此,它可以支持:int pOw(int,int);双PoW(double,double);在C编译的库中,应该用多次定义的符号来获得错误,链接器不知道该选择哪一个(或者它总是选择第一个定义,然后你会得到奇怪的行为)。在一个C++编译的库中,名字将被修改,C++编译器/链接器将知道根据参数使用哪一个。在大多数情况下,在嵌入式系统中,当你在混合C++C++时,你希望使用C库,除非你需要像上面提到的那样重载。这样一来,你的C代码和C++代码都将使用相同的符号,并且由于名称的篡改和使用Flash空间,你不会有重复的目标代码。(注:一些编译器/链接器将找到重复的对象代码,并将所有的东西指向一个副本,并删除其他副本。我不知道XC32是否这样做。从你所写的看来,你将需要C和C++版本的代码,因为该库使用C++数学函数。
以上来自于百度翻译
以下为原文
I can't say for your specific application. What I can say is:
C++ libraries can call C libraries.
But C++ supports overloading. So it can support for example:
- int pow(int, int);
- double pow(double, double);
In a C compiled library you should get errors with symbols defined multiple times, and the linker wouldn't know which to choose (or it'll always choose the first one defined and then you'll get strange behavior). In a C++ compiled library the names will be mangled and the C++ compiler/linker will know which one to use based on the parameters.
In most cases on an embedded system when you're mixing C & C++ you want to use the C libraries unless you need something like overloading as I stated above. This way both your C code and your C++ code will use the same symbol and you won't have object code duplicated because of the name mangling and using up flash space.
(One note: some compilers/linkers will find the duplicated object code and point everything to one copy and eliminate the others. I don't know if XC32 does this).
From what you wrote it looks like you will need both the C and C++ versions of the code because that library uses the C++ math functions.
举报