LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-13-2008, 06:35 PM   #1
crapodino
Member
 
Registered: Aug 2005
Distribution: SuSE 10
Posts: 72

Rep: Reputation: 15
undefined reference to....


Hi! i am trying to compile/link a simple application that uses a library called OpenDBX. I have already compiled and installed that library. Now, i am trying to do a simple client of it.

The client (Prueba.c) is just like this:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <odbx.h>

int main(void) {
	puts("Hello World!!");
	
		int err;
		odbx_t* handle;
	
		if( ( err = odbx_init( &handle, "mysql", "127.0.0.1", "" ) ) < 0 )
		{
		    fprintf( stderr, "odbx_init(): %s\n", odbx_error( handle, err ) );
		    return err;
		}
		
		return EXIT_SUCCESS;
}


When i try to compile that program (Prueba.c), i has this error:

cc -c -o Prueba.o Prueba.c
gcc -O2 -g -Wall -fmessage-length=0 -L/usr/local/lib -L/usr/local/lib/opendbx -L/usr/local/lib/pkgconfig -o Pruebas Prueba.o
Prueba.o: In function `main':
Prueba.c.text+0x3c): undefined reference to `odbx_init'
Prueba.c.text+0x57): undefined reference to `odbx_error'
collect2: ld returned 1 exit status
make: *** [Pruebas] Error 1


Those functions (odbx_error and odbx_init are both defined in odbx.h (the header of openDBX y need to include).

I have checked that openDBX libraries are okey. There are in /usr/local/lib , /usr/local/lib/opendbx and /usr/local/lib/pkgconfig.

My makefile is like this:

Code:
COMPILER = gcc

CCFLAGS =	-O2 -g -Wall -fmessage-length=0 

OBJS =		Prueba.o

LIBS = 

TARGET =	Pruebas

LDFLAGS = -L/usr/local/lib -L/usr/local/lib/opendbx -L/usr/local/lib/pkgconfig

$(TARGET):	$(OBJS)
	${COMPILER} ${CCFLAGS} $(LDFLAGS) -o $(TARGET) $(OBJS) $(LIBS)

all:	$(TARGET)

clean:
	rm -f $(OBJS) $(TARGET)
So...can someone please tell what does this error mean ? i think that it doesn't found the library asosiated with de odbx.h, but i am not sure.

Very thanks

Mariano
 
Old 01-13-2008, 07:05 PM   #2
osor
HCL Maintainer
 
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450

Rep: Reputation: 77
Quote:
Originally Posted by crapodino View Post
Hi! i am trying to compile/link a simple application that uses a library called OpenDBX. I have already compiled and installed that library. Now, i am trying to do a simple client of it.
So I presume you never found the solution to your other problem?
Quote:
Originally Posted by crapodino View Post
The client (Prueba.c) is just like this:
[CODE]So...can someone please tell what does this error mean ? i think that it doesn't found the library asosiated with de odbx.h, but i am not sure.
Yes, that’s exactly what it means—you don’t have any libraries specified (though you do have a library search path).

Here’s how I would modify your Makefile:
Code:
COMPILER = gcc

ODBX_CFLAGS := $(shell pkg-config --cflags opendbx)
ODBX_LIBS   := $(shell pkg-config --libs   opendbx)

CCFLAGS =	-O2 -g -Wall -fmessage-length=0 $(ODBX_CFLAGS)

OBJS =		Prueba.o

LIBS = 		$(ODBX_LIBS)

TARGET =	Pruebas

LDFLAGS = -L/usr/local/lib -L/usr/local/lib/opendbx -L/usr/local/lib/pkgconfig

$(TARGET):	$(OBJS)
	${COMPILER} ${CCFLAGS} $(LDFLAGS) -o $(TARGET) $(OBJS) $(LIBS)

all:	$(TARGET)

clean:
	rm -f $(OBJS) $(TARGET)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Undefined reference, why? george_mercury Programming 4 05-07-2009 12:15 AM
Undefined reference to: ashlesha Programming 5 11-08-2006 01:07 PM
undefined reference vkmgeek Programming 1 05-11-2006 06:37 AM
Undefined Reference ChemicalBurn Programming 2 02-14-2005 03:01 AM
undefined reference mp4-10 Programming 3 01-25-2005 12:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration