سؤال

{net04:~/xxxx/wip} gcc -o  write_test write_test.c
In file included from write_test.c:4:
global.h:10: warning: `b' initialized and declared `extern'

يستخدم هذا الرمز fcntl.h ووظائف معالجة الملفات المحددة - مثل Open () ، write () ، elut () etc .. تجمع الكود ويعمل على النحو المقصود.

{net04:~/xxxx/wip} gcc -o  write_test write_test.cpp
In file included from write_test.cpp:4:
global.h:10: warning: `b' initialized and declared `extern'
write_test.cpp: In function `int main()':
write_test.cpp:56: error: `exit' undeclared (first use this function)
write_test.cpp:56: error: (Each undeclared identifier is reported only once for each function it appears in.)
write_test.cpp:58: error: `write' undeclared (first use this function)
write_test.cpp:62: error: `close' undeclared (first use this function)

عندما أستخدمه كرمز مصدر CPP ، لماذا تشكو GCC؟ وفضولي ، لماذا لا تشكو من Open ()؟ ما الذي يحدث حتى هنا؟

هل كانت مفيدة؟

المحلول

  1. C ++ أكثر صرامة حول الرؤوس - تحتاج: #include <unistd.h> للحصول على الوظائف المشار إليها بشكل صحيح.

  2. global.h لا ينبغي أن تحدد الرؤوس B - لا ينبغي أن تهيئة المتغيرات.

  3. عند التجميع يجب أن تستخدم -Wall -Werror وهذا سيجبرك على إصلاح جميع أجزاء الكود المراوغة.

  4. للحصول على exit() نظيفة ستحتاج #include <cstdlib> (C ++) أو #include <stdlib.h> (ج)

  5. يستخدم g++ لربط رمز C ++ بحيث يتم تضمين مكتبات C ++. ربما أسهل للقيام بتجميع C ++ بأكمله g++.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top