CではOKなのに
■ このスレッドは過去ログ倉庫に格納されています
0001名無しさん@お腹いっぱい。
NGNGエラーになってしまいます。
CではOKなのに、なぜC++ではダメなのでしょうか?
OSはLinux、コンパイラはgccです。
#include <stdio.h>
#include <string.h>
#define ERR -1
void usage();
char *command_name;
int main( int argc@` char* argv[] )
{
int pid;
int status;
if (( command_name = strrchr(argv[0]@` '/')) != NULL ) {
command_name++;
}
else {
command_name = argv[0];
}
if ( argc < 2 ) {
usage();
return 1;
}
if ( ( pid = fork() ) == 0 ) {
/* Child process */
printf("Child process : execute a new program %s. \n"@` argv[1] );
if ( execvp( argv[1]@` &argv[1] ) == ERR ) {
perror("execvp");
return 1;
}
}
else if ( pid >= 1 ) {
/* Parent process */
wait( &status );
printf("Parent process : child process has just finished. \n");
printf("status = %04x\n"@` status );
}
else {
perror("fork");
return 1;
}
return 0;
}
void usage()
{
fprintf( stderr@` "Usage: %s command \n"@` command_name );
}
0002名無しさん@お腹いっぱい。
NGNG0003単発質問はヤメレ
NGNG・あなたの宿題、お姉さんが答えます
http://piza.2ch.net/test/read.cgi?bbs=tech&key=972032579
・( ゚Д゚)ノ ギコ猫のプログラム相談室
http://piza.2ch.net/test/read.cgi?bbs=tech&key=971446820
・C言語なら、オレに聞け!
http://piza.2ch.net/test/read.cgi?bbs=tech&key=967985026
・C言語プログラムのの添削お願いします。
http://piza.2ch.net/test/read.cgi?bbs=tech&key=973920435
0004単発質問はヤメレ
NGNGすいません、>>3のは無しです
・あなたの宿題、お姉さんが答えます
http://piza.2ch.net/test/read.cgi?bbs=tech&key=972032579
・( ゚Д゚)ノ ギコ猫のプログラム相談室
http://piza.2ch.net/test/read.cgi?bbs=tech&key=971446820
・C言語なら、オレに聞け!
http://piza.2ch.net/test/read.cgi?bbs=tech&key=967985026
これは荒らされているので放置
・C言語プログラムのの添削お願いします。
ttp://piza.2ch.net/test/read.cgi?bbs=tech&key=973920435
0005名無しさん@お腹いっぱい。
NGNGChange.cpp
c:\windows\デスクトップ\プログラム\myproject\change.cpp(25) : error C2065: 'fork' : 定義されていない識別子です。
c:\windows\デスクトップ\プログラム\myproject\change.cpp(28) : error C2065: 'execvp' : 定義されていない識別子です。
c:\windows\デスクトップ\プログラム\myproject\change.cpp(35) : error C2065: 'wait' : 定義されていない識別子です。
cl.exe の実行エラー
Change.obj - エラー 3、警告 0
0006C++厨房
NGNGextern int fork();
extern int execvp( char* file@` char* argv[] );
extern int wait( int* stat_loc );
を追加してコンパイルしてみたら
コンパイルはOKでしたが、リンクでだめでした。
なぜ?
0007名無しさん@お腹いっぱい。
NGNG0008名無しさんi486
NGNG0009名無しさん@お腹いっぱい。
NGNG$ gcc -o 1 1.cc
1.cc: In function `int main(int@` char **)':
1.cc:25: warning: implicit declaration of function `int fork(...)'
1.cc:28: warning: implicit declaration of function `int execvp(...)'
1.cc:35: warning: implicit declaration of function `int wait(...)'
00109へ
NGNGでもやってみて!
0012C++厨房
NGNG1のプログラムの #define ERR -1 の下に
extern int fork();
extern int execvp( char* file@` char* argv[] );
extern int wait( int* stat_loc );
を追加し、
g++ -o 1 1.cxxとすると
/tmp/cchdEwUM.o: In function `main':
1.cxx(.text+0xa4): undefined reference to `fork(void)'
1.cxx(.text+0xa8): undefined reference to `fork(void)'
1.cxx(.text+0xfc): undefined reference to `execvp(char *@` char **)'
1.cxx(.text+0x100): undefined reference to `execvp(char *@` char **)'
1.cxx(.text+0x14c): undefined reference to `wait(int *)'
1.cxx(.text+0x150): undefined reference to `wait(int *)'
collect2: ld returned 1 exit status
となってしまう。
ちなみに、環境はLinux/Alpha@` gcc version 2.95.2
やっぱり、俺って厨房?
00139
NGNG>extern int fork();
>extern int execvp( char* file@` char* argv[] );
>extern int wait( int* stat_loc );
こんなもの↑は、取っ払って、↓のインクルード追加しな
#include <unistd.h>
#include <wait.h>
0014名無しさん@お腹いっぱい。
NGNG0015神
NGNG=========== このスレ終了 ===========================
0016名無しさん@お腹いっぱい。
NGNG■ このスレッドは過去ログ倉庫に格納されています