سؤال
{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 ()؟ ما الذي يحدث حتى هنا؟
المحلول
C ++ أكثر صرامة حول الرؤوس - تحتاج:
#include <unistd.h>
للحصول على الوظائف المشار إليها بشكل صحيح.global.h
لا ينبغي أن تحدد الرؤوس B - لا ينبغي أن تهيئة المتغيرات.عند التجميع يجب أن تستخدم
-Wall -Werror
وهذا سيجبرك على إصلاح جميع أجزاء الكود المراوغة.للحصول على
exit()
نظيفة ستحتاج#include <cstdlib>
(C ++) أو#include <stdlib.h>
(ج)يستخدم
g++
لربط رمز C ++ بحيث يتم تضمين مكتبات C ++. ربما أسهل للقيام بتجميع C ++ بأكملهg++
.
لا تنتمي إلى StackOverflow