C言語コンパイルエラーの原因と対処法

このQ&Aのポイント
  • C言語のプログラムをコンパイルした際にエラーメッセージが表示されました。このエラーメッセージは、プログラムにミスがあることを意味しています。
  • 具体的には、'/tmp/cchzThVk.o: In function 'c_to_sh': 5.c:(.text+0x5b3): undefined reference to 'sqrt' 5.c:(.text+0x64e): undefined reference to 'atan2' collect2: Id は ステータス1で終了しました。'というメッセージが表示されました。
  • このエラーメッセージは、sqrtやatan2といった関数が見つからないことを示しています。プログラムでこれらの関数を使用している場合は、適切なヘッダーファイルをインクルードする必要があります。
回答を見る
  • ベストアンサー

c言語 コンパイルエラー

以下webページに載っているC言語のプログラムをコンパイルした時に ”/tmp/cchzThVk.o: In function 'c_to_sh': 5.c:(.text+0x5b3): undefined reference to 'sqrt' 5.c:(.text+0x64e): undefined reference to 'atan2' collect2: Id は ステータス1で終了しました。” とメッセージが出るのですが、このメッセージが出たときはプログラムにミスがあるということなのでしょうか。教えてくださいお願いします。 http://plaza.rakuten.co.jp/dragonkkk

質問者が選んだベストアンサー

  • ベストアンサー
  • sakusaker7
  • ベストアンサー率62% (800/1280)
回答No.1

どんな環境でどんなコンパイラを使っているのかわかりませんが、 メッセージから判断するとUnixぽいので cc ファイル名 -lm と後ろに -lm ってオプションを追加してみてください。

ketchupk
質問者

お礼

うまくコンパイルできました。どうもありがとうございました。

関連するQ&A

  • C言語の画像抽出

    C言語のプログラムをコンパイルした時に ”/tmp/cchzThVk.o: In function 'c_to_sh': 5.c:(.text+0x5b3): undefined reference to 'sqrt' 5.c:(.text+0x64e): undefined reference to 'atan2' collect2: Id は ステータス1で終了しました。” とメッセージが出るのですが、このメッセージが出たときはプログラムにミスがあるということなのでしょうか。教えてくださいお願いします。

  • C言語プログラムの質問なんですが、エラーが出てコンパイルできません。

    C言語プログラムの質問なんですが、エラーが出てコンパイルできません。 エラーメッセージ /tmp/ccGHoP41.o: In function `main': step1-7.c:(.text+0x39): undefined reference to `stringStdin' collect2: ld returned 1 exit status 何が間違ってるのか全くわからない状態です。 どなたかアドバイスお願いします!

  • プログラミングのコンパイルで・・・・・

    C言語でのコンパイルで /tmp/cckxNO3W.o(.text+0xce): In function `main': : undefined reference to `hukeisan' collect2: ld はステータス 1 で終了しました と出るのですがどうしたらいいですか。教えてください。

  • PostgreSQLをC言語でアクセスしようと

    PostgreSQL 8.4.8 文書にのっているサンプルプログラムの 例 30-1. libpq サンプルプログラム 1 #include <stdio.h> #include <stdlib.h> #include "libpq-fe.h" ・・・・・・・・・・・・・ をコピペしてコンパイルしたところ次のようなエラーがでました # gcc sample.c /tmp/cctZBolQ.o: In function `exit_nicely': sample.c:(.text+0xd): undefined reference to `PQfinish' /tmp/cctZBolQ.o: In function `main': sample.c:(.text+0x4a): undefined reference to `PQconnectdb' sample.c:(.text+0x5a): undefined reference to `PQstatus' sample.c:(.text+0x6a): undefined reference to `PQerrorMessage' sample.c:(.text+0xa5): undefined reference to `PQexec' sample.c:(.text+0xb5): undefined reference to `PQresultStatus' sample.c:(.text+0xc6): undefined reference to `PQerrorMessage' sample.c:(.text+0xed): undefined reference to `PQclear' sample.c:(.text+0x105): undefined reference to `PQclear' sample.c:(.text+0x119): undefined reference to `PQexec' sample.c:(.text+0x129): undefined reference to `PQresultStatus' sample.c:(.text+0x13a): undefined reference to `PQerrorMessage' sample.c:(.text+0x161): undefined reference to `PQclear' sample.c:(.text+0x179): undefined reference to `PQclear' sample.c:(.text+0x18d): undefined reference to `PQexec' sample.c:(.text+0x19d): undefined reference to `PQresultStatus' sample.c:(.text+0x1ae): undefined reference to `PQerrorMessage' sample.c:(.text+0x1d5): undefined reference to `PQclear' sample.c:(.text+0x1ed): undefined reference to `PQnfields' sample.c:(.text+0x20f): undefined reference to `PQfname' sample.c:(.text+0x26b): undefined reference to `PQgetvalue' sample.c:(.text+0x2a8): undefined reference to `PQntuples' sample.c:(.text+0x2ba): undefined reference to `PQclear' sample.c:(.text+0x2ce): undefined reference to `PQexec' sample.c:(.text+0x2de): undefined reference to `PQclear' sample.c:(.text+0x2f2): undefined reference to `PQexec' sample.c:(.text+0x302): undefined reference to `PQclear' sample.c:(.text+0x30e): undefined reference to `PQfinish' collect2: ld はステータス 1 で終了しました # # find /usr/include/ -name libpq*.h /usr/include/pgsql/internal/libpq-int.h /usr/include/pgsql/server/libpq/libpq-be.h /usr/include/pgsql/server/libpq/libpq.h /usr/include/pgsql/server/libpq/libpq-fs.h /usr/include/libpq/libpq-fs.h /usr/include/libpq-events.h /usr/include/libpq-fe.h # gcc -I/usr/include sample.c でもおなじです どうすればコンパイル出きるようになるでしょうか? よろしくお願いします

  • C言語

    コンパイルしたときに /tmp/cceF11bH.o(.txet+0*1de):ln function 'hilbert.'0 : : undefined reference to 'hilbert' collect2 :ld はステータス1 で終了しました と表示されます。 どういう意味でしょうか?

  • コンパイル時のエラー

    UNIXでサーバー、クライアントのCプログラミングをテキストどおりに書いてコンパイルしたのですが、以下のエラーが出ます。gcc, ccでコンパイルすると以下のようになるのですが、これはどういうことなのでしょうか?何が原因なのでしょうか?よろしくお願いいたします。 gcc unix_server.c /var/tmp/ccvpay1f1.o: In function `main': /var/tmp/ccvpay1f1.o(.text+0x8c): undefined reference to `socket' /var/tmp/ccvpay1f1.o(.text+0x104): undefined reference to `unllnk' /var/tmp/ccvpay1f1.o(.text+0x118): undefined reference to `bind' /var/tmp/ccvpay1f1.o(.text+0x150): undefined reference to `listen' /var/tmp/ccvpay1f1.o(.text+0x1a8): undefined reference to `accept' cc unix_server.c ld: /usr/lib/cmplrs/cc/crtn.o: Error: Unresolved: rindex socket bzero bcopy unllnk bind listen accept

  • コンパイルエラーについて

    関数 y=x と y=x*x/8 のグラフをテキストで描くプログラムなのですが、cygwinでコンパイルすると次のエラーが出ます。何を直せばいいのか教えてください。 /tmp/cceveo7s.o:week2.c:(.text+0x62): undefined reference to `_f' /tmp/cceveo7s.o:week2.c:(.text+0xb1): undefined reference to `_f' /tmp/cceveo7s.o:week2.c:(.text+0xbd): undefined reference to `_g' collect2: ld はステータス 1 で終了しました ソースプログラムはこちらです。 #include <stdio.h> #define XSIZE 20 #define YSIZE 20 char graph[XSIZE][YSIZE]; /* 座標(x, y)に文字cをプロットする */ void f(int x, int y, char c); /* 作成したグラフを表示する */ void g(void); int main(void){ int x, y; for (x=0;x<XSIZE;x++){ y = x; f(x, y, '+'); } for (x=0 ; x < XSIZE ; x++){ y=x*x/8 ; f(x, y, '*'); if(y>=YSIZE) break; g(); return 0; } void f(int x, int y, char c) { graph[x][y] = c; } void g(void) { int a, b; for (b=YSIZE ; b>0 ; b--){ for (a = 0 ; a < XSIZE ; a++){ if (graph[a][b]==0) printf(" "); else printf("%c ", graph[a][b]); } printf("\n"); } } return 0; }

  • Linux GTK+でのコンパイルエラー

    GKT+でプログラミングをしたいと思い、下記のサイトを見ながらサンプルプログラムをコンパイルしたら下のようなエラーが表示されました。原因が全くわからず困っています。わかる方教えてください。 【参考にしたサイト】 http://samidarehetima.web.fc2.com/howtogtk/top.html#toc_1 【コード】 #include <gtk/gtk.h> //ボタンがクリックされたときに呼び出される関数 static void button_clicked(GtkWidget *button, gpointer user_data) { gtk_main_quit(); } int main(int argc, char** argv){ GtkWidget *window; gtk_init(&argc,&argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_size_request(window,300,200); { //ボタンを作成する。 GtkWidget *button; button = gtk_button_new_with_label("Quit"); //ボタンをwindowに乗っける。 gtk_container_add(GTK_CONTAINER(window), button); //ボタンにclickedと表示し,押された時はbutton_clicked()を呼び出す。 g_signal_connect (G_OBJECT(button), "clicked" , G_CALLBACK(button_clicked), NULL); } g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); //windowの上にある物も全て表示する。(_allが付くことに注意) gtk_widget_show_all(window); gtk_main(); return 0; } 【エラー】 /tmp/ccmjmPda.o: In function `button_clicked': test.c:(.text+0x7): undefined reference to `gtk_main_quit' /tmp/ccmjmPda.o: In function `main': test.c:(.text+0x25): undefined reference to `gtk_init' test.c:(.text+0x31): undefined reference to `gtk_window_new' test.c:(.text+0x51): undefined reference to `gtk_widget_set_size_request' test.c:(.text+0x5d): undefined reference to `gtk_button_new_with_label' test.c:(.text+0x66): undefined reference to `gtk_container_get_type' test.c:(.text+0x76): undefined reference to `g_type_check_instance_cast' test.c:(.text+0x86): undefined reference to `gtk_container_add' test.c:(.text+0x9f): undefined reference to `g_type_check_instance_cast' test.c:(.text+0xcb): undefined reference to `g_signal_connect_data' test.c:(.text+0xeb): undefined reference to `gtk_main_quit' test.c:(.text+0xff): undefined reference to `g_signal_connect_data' test.c:(.text+0x10b): undefined reference to `gtk_widget_show_all' test.c:(.text+0x110): undefined reference to `gtk_main' collect2: ld はステータス 1 で終了しました

  • コンパイルエラーの意味

    最近プログラミングの勉強を始めた初心者です。作成したプログラムをコンパイルしたところ以下のようなエラーが出ましたがなんのエラーなのかまったく分かりません… 初歩的な質問で申し訳ありませんが教えてください! /user/lib/libcygwin.a(libcmain.o)(.text+0x6a):libcmain.c: undefined reference to'WinMain@16' collect2: ld returned 1 exit status

  • sendmailのコンパイルエラーについて

    教えてください。>_< お願いします。 sendmail-8.12.2のインストールを試みたのですが、 エラーが返ってきます。 このエラーの意味、対処法などご存知の方 教えてください。 <エラー内容> domain.o: In function `getmxrr': domain.o(.text+0x25f): undefined reference to `__res_query' domain.o(.text+0x266): undefined reference to `__res_search' domain.o(.text+0x39b): undefined reference to `__dn_skipname' domain.o(.text+0x496): undefined reference to `__dn_expand' domain.o(.text+0x603): undefined reference to `__dn_expand' domain.o: In function `dns_getcanonname': domain.o(.text+0xf0c): undefined reference to `__res_querydomain' domain.o(.text+0x100f): undefined reference to `__dn_skipname' domain.o(.text+0x123f): undefined reference to `__dn_expand' domain.o(.text+0x128a): undefined reference to `__dn_expand' sm_resolve.o: In function `parse_dns_reply': sm_resolve.o(.text+0x17e): undefined reference to `__dn_expand' sm_resolve.o(.text+0x1fe): undefined reference to `__dn_expand' sm_resolve.o(.text+0x2e5): undefined reference to `__dn_expand' sm_resolve.o(.text+0x337): more undefined references to `__dn_expand' follow sm_resolve.o: In function `dns_lookup_int': sm_resolve.o(.text+0x612): undefined reference to `__res_search' collect2: ld returned 1 exit status make: *** [sendmail] エラー1 gccはバージョン2.96-81です。 OSはRedhatLinux7.1Jです。 よろしくお願いします。m(_)m

専門家に質問してみよう