C와 mysql 을 연동했을때 컴파일 문제.....

nineorb의 이미지

배포본은 맨드레이크 9.1 쓰고 있습니다.

c를 이용해 mysql을 제어 하려고 cgi파일을 만들기 위해 컴파일을 하면

/tmp/ccoUo6GW.o(.text+0x45): In function `main':
: undefined reference to `mysql_connect'
collect2: ld returned 1 exit status

라고 달랑 세줄의 에러가 뜨는군요.... 장황하게 뜨면 뭔가가 잘못된건지

집작이라도 할수 있을거 같은데.... 달랑 세줄이라니...

컴파일 옵션은 다음과 같이 주었습니다.

gcc -o neon.cgi neon.c qDecoder.c -I/usr/include/mysql -L/usr/lib/mysql -lmysqlclient -lnsl

틀린것은 없는거 같은데 뭐가 잘못된건지 모르겠네요..

같은 환경에서 똑같은 옵션으로 컴파일 했을때 레드햇9는 잘됩니다...

코드는 다음과 같습니다.

#include <stdio.h>
#include "mysql.h"
#include "qDecoder.h"
#define MAX_LENGTH 100

int main()
{
		MYSQL_RES *result;
		MYSQL_ROW row;
		MYSQL connection;

		int i;
		char *name;
		char *num;
		char query[MAX_LENGTH];

		qDecoder();
		num=qValue("num");

		mysql_connect(&connection,"localhost","root","dkdiskal");
		mysql_select_db(&connection,"nineorb");
		sprintf(query, "delete from name where num='%s'", num);
		mysql_query(&connection, query);
		
//		if(!(result=mysql_store_result(&connection)))
		
		memset(query, 0x00, sizeof(query));
		sprintf(query, "select * from name order by num desc");
		mysql_query(&connection, query);
			
		result=mysql_store_result(&connection);
		
		printf("content-Type:text/html\n\n");
		printf("<HTML>");
		printf("<BODY>");
										                                                             
		printf("<table border=2 align=center>");

		while((row=mysql_fetch_row(result))!=NULL)
		{
				printf("<tr>\n");
//				for (i=0; i<mysql_num_fields(result);i++)
				printf("<td>%s</td>",row[0]);
				printf("<td>%s</td>",row[1]);
				printf("<td><a href=name_delete.cgi?num=%s>삭제</a></td>",row[0]);
				printf("<td><a href=name_update.cgi?num=%s&name=%s>수정</a></td>",row[0],row[1]);
				printf("</tr>\n");
		}
		printf("</table>");
		printf("<br>");

		printf("</body>");
		printf("</html>");

		mysql_free_result(result);
		mysql_close(&connection);
}

어떻게 해결해야 할까요??? 레드햇에서는 되는거 보니 뭔가 설정이

잘못된거 같은데..

hurryon의 이미지

-lm -lsocket 을 빼먹은건 아닌지요?

linuxs의 이미지

음 저도 예전에 비슷한 경험을 했었어요
mysql shared 라이브러리를 알려줘야 되요.
다시말하면 /etc/ld.so.conf에 libmysqlclient 위치를
적은다음에
ldconfig라는 명령어 한번 쳐주고 해보세요

꿈은 이루어진다.

pynoos의 이미지

nineorb wrote:
배포본은 맨드레이크 9.1 쓰고 있습니다.

혹시 libmysqlclient.a 가 없는것 아닙니까?

mastercho의 이미지

마지막에 -lm 이거 옵션을 줘야 한다는거 같은데

잘은 몰겠고요

제 mysql 책에는 글케 컴파일하는 모습이

승자는 자기보다 우월한 사람을 보면 존경심을 갖고 그로부터 배울 점을 찾지만 패자는 자기보다 우월한 사람을 만나면 질투심을 갖고 어디 구멍난 곳이 없는지 찾는다.
- 하비스

ycode의 이미지

위의 분들 말씀처럼 mysql 라이브러리랑 인클루드 패스를 확인해보시는게 좋을듯합니다. 예전에 저도 비슷한 경험이 있었는데, 결국

-L/usr/local/mysql/lib/mysql
-I/usr/local/mysql/include/mysql

로 패스가 다르게 설치되어 있더군요.

charsyam의 이미지

ld.so.conf 에 추가하시고

ldconfig 를 해주시던지

아니면 개인 쉘에(루트 권한이 없다면)

LD_LIBRARY_PATH 를 잡아주시면 됩니다.

고운하루되시길...

=========================
CharSyam ^^ --- 고운 하루
=========================

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.