Почему, когда я хочу скомпилировать следующую многопоточную программу сортировки слиянием, я получаю эту ошибку:
Решение
ни ни являются стандартными заголовочными файлами C. Ваш код предназначен для C ++, где является действительным заголовком. использование g++ (и .cpp расширение файла) для кода C ++.
Кроме того, эта программа использует в основном конструкции, которые в любом случае доступны в Си. Достаточно просто преобразовать всю программу для компиляции с использованием компилятора Си. Просто удалить #include а также using namespace std; и заменить cout с putchar(‘
‘); … советую компилировать с использованием C99 (например. gcc -std=c99 )
Другие решения
Похоже, вы опубликовали новый вопрос после того, как поняли, что имеете дело с более простой проблемой, связанной с size_t , Я рад, что ты это сделал.
В любом случае, у вас есть .c исходный файл, и большая часть кода выглядит в соответствии со стандартами C, за исключением того, что #include а также using namespace std;
C эквивалент для встроенных функций стандарта C ++ #include можно получить через #include
-
замещать #include с #include , удалять using namespace std;
С #include снял, вам понадобится стандартная альтернатива С для cout что может быть сделано printf(»
«); или же putchar(‘
‘);
Из двух вариантов, printf(»
«); работает быстрее, как я заметил.
Когда используется printf(»
«); в приведенном выше коде вместо cout
Когда используется putchar(‘
‘); в приведенном выше коде вместо cout
Скомпилировано с Cygwin gcc (GCC) 4.8.3 версия. результаты усреднены по 10 выборкам. (Заняло у меня 15 минут)
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto | Site FAQ | Sitemap | Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
| Introduction to Linux — A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter. For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author’s experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own. Why when I wan to compile the following multi thread merge sorting C program, I receive this error:
2 Answers 2Neither nor are standard C header files. Your code is meant to be C++, where is a valid header. Use g++ (and a .cpp file extension) for C++ code. Alternatively, this program uses mostly constructs that are available in C anyway. It’s easy enough to convert the entire program to compile using a C compiler. Simply remove #include and using namespace std; , and replace cout with putchar(‘
Seems like you posted a new question after you realized that you were dealing with a simpler problem related to size_t . I am glad that you did. Anyways, You have a .c source file, and most of the code looks as per C standards, except that #include and using namespace std; C equivalent for the built-in functions of C++ standard #include can be availed through #include
With #include taken off, you would need a C standard alternative for cout , which can be done by printf(» When used printf(» When used putchar(‘ Compiled with Cygwin gcc (GCC) 4.8.3 version. results averaged over 10 samples. (Took me 15 mins) |

