Компиляция смешанного кода C/C ++ с C -кодом с использованием GMP -библиотекиC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Компиляция смешанного кода C/C ++ с C -кодом с использованием GMP -библиотеки

Сообщение Anonymous »

У меня есть проект, состоящий из файлов c и c ++ . Код файла C использует библиотеку GMP . Файл c ++ содержит функцию Main и вызывает функцию из файла c .

Код: Выделить всё

point.h< /code>
< /p>
#ifndef POINT_H
#define POINT_H

#ifdef __cplusplus
extern "C" {
#endif

#include 

typedef struct {
mpz_t x;
mpz_t y;
} Point;

void init_point(Point* p);
void clear_point(Point* p);
void print_point(const Point* p);

#ifdef __cplusplus
}
#endif

#endif  // POINT_H
< /code>
point.c< /code>
< /p>
#include 
#include "point.h"

void init_point(Point* p) {
mpz_init(p->x);
mpz_init(p->y);
mpz_set_ui(p->x, 42);
mpz_set_ui(p->y, 17);
}

void clear_point(Point* p) {
mpz_clear(p->x);
mpz_clear(p->y);
}

void print_point(const Point* p) {
gmp_printf("Point(x = %Zd, y = %Zd)\n", p->x, p->y);
}
< /code>
main.cpp< /code>
< /p>
extern "C" {
#include "point.h"
}

int main() {
Point p;
init_point(&p);
print_point(&p);
clear_point(&p);
return 0;
}
< /code>
The C
Файл -объект создается, но C ++ One не:

Код: Выделить всё

[ 33%] Building C object CMakeFiles/gmp_example.dir/point.c.o
[ 66%] Building CXX object CMakeFiles/gmp_example.dir/main.cpp.o
In file included from /usr/include/c++/13/bits/stringfwd.h:40,
from /usr/include/c++/13/iosfwd:41,
from /usr/include/x86_64-linux-gnu/gmp.h:35,
from /mnt/HDD_Small/Bitcoin_Jumper/src/gmp/point.h:8,
from /mnt/HDD_Small/Bitcoin_Jumper/src/gmp/main.cpp:2:
/usr/include/c++/13/bits/memoryfwd.h:64:3: error: template with C linkage
64 |   template
|   ^~~~~~~~
/mnt/HDD_Small/Bitcoin_Jumper/src/gmp/point.h:5:1: note: ‘extern "C"’ linkage started here
5 | extern "C" {
| ^~~~~~~~~~
/usr/include/c++/13/bits/memoryfwd.h:67:3: error: template specialization with C linkage
67 |   template
|   ^~~~~~~~
/mnt/HDD_Small/Bitcoin_Jumper/src/gmp/point.h:5:1: note: ‘extern "C"’ linkage started here
5 | extern "C" {
| ^~~~~~~~~~
/usr/include/c++/13/bits/memoryfwd.h:73:3: error: template with C linkage
73 |   template
|   ^~~~~~~~
/mnt/HDD_Small/Bitcoin_Jumper/src/gmp/point.h:5:1: note: ‘extern "C"’ linkage started here
5 | extern "C" {
| ^~~~~~~~~~

...

/usr/include/c++/13/iosfwd:217:3: error: template with C linkage
217 |   template>(std::istream&, mpz_ptr)’
2295 | __GMP_DECLSPEC_XX std::istream& operator>> (std::istream &, mpz_ptr);
|                                 ^~~~~~~~
make[2]: *** [CMakeFiles/gmp_example.dir/build.make:93: CMakeFiles/gmp_example.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:87: CMakeFiles/gmp_example.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
< /code>
I tried moving the extern "C"
в файле c в разные места попытались удалить его, но ничего не сработало. Потратили полдня, но без успеха (хотя некоторые тесты без GMP были успешными).
Вопрос: в чем корень проблемы?

Подробнее здесь: https://stackoverflow.com/questions/796 ... mp-library
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»