Compilerfehler C-Laibrary in C++ Verwenden
-
Hallo!
ich würde Funktionen von C-Library in C++ programm verwenden und habe die mit extern C eingebindet aber es hat nicht geklappt; weis Jemand wie ich die include bzw. in Makefile hinzufüge :
#include<iostream> # #include<cstring> #include<utility> #include <cstdio> #include <cstdlib> #include <cstring> #include <cassert> extern "C" { #include <matheval.h> } using namespace std; int main() {
hier ist die Makefile:
test1: main.o g++ -o test1 main.o main.o:main.cpp g++ -c main.cpp clean: rm test1 main.o #that's alle
Complirfehler:
ake -k g++ -o test1 main.o main.o: In function `main': main.cpp:(.text+0x84): undefined reference to `evaluator_create' main.cpp:(.text+0xde): undefined reference to `evaluator_get_variables' main.cpp:(.text+0x206): undefined reference to `evaluator_evaluate_x' main.cpp:(.text+0x2f0): undefined reference to `evaluator_destroy' collect2: ld returned 1 exit statu
Danke schönmal im Voraus
Gruß
Seb
-
Das kommt ganz darauf an, wie du die Library vorliegen hast. Aber vermutlich mußt du die matheval.o mit an den Linker übergeben, damit der sie auch findet.
-
entweder habe ich die falsch an die Linke übergibt oder es liegt doch an dem Compiler der findet das nicht; so habe es übergibt
test1: main.o g++ -o test1 lmatheval.o main.o main.o:main.cpp g++ -c main.cpp clean: rm test1 main.o #that's all
Compilermeldung:
g++ -o test1 lmatheval.o main.o g++: error: lmatheval.o: Datei oder Verzeichnis nicht gefunden make: *** [test1] Fehler 1
habe auch statt lmatheval.o matheval.o übergit
-
Dieser Thread wurde von Moderator/in CStoll aus dem Forum C++ (auch C++0x) in das Forum Compiler- und IDE-Forum verschoben.
Im Zweifelsfall bitte auch folgende Hinweise beachten:
C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?Dieses Posting wurde automatisch erzeugt.
-
Hast du die C-Library denn fertig compiliert verfügbar oder im Quelltext? Wenn ersteres, ist es vermutlich eine .a- oder .lib-Datei, die du dem Linker geben mußt. Wenn du den Quelltext verfügbar hast, mußt du sie noch selber übersetzen, um die .o Datei zu bekommen.
(btw, ich erinnere mit zwar nur düster, aber afair müsste es "-l matheval" heißen)
-
CStoll schrieb:
(btw, ich erinnere mit zwar nur düster, aber afair müsste es "-l matheval" heißen)
Auch das kommt ganz drauf an, was der Threadersteller vorliegen hat. (Und normalerweise ohne Leerzeichen)
-
ich habe die library schöne in Qt-programm ohne Problem verwendet und habe nur
folgendes gemacht:
main.cpp#include <cassert> extern "C" { #include <matheval.h> } using namespace std; int main( int argc, char *argv[]) {
und in makefile habe ich sie mit den anderen qt-librarys den liker so übergegeben:
hier ist ein Abschnitt von Makefile:CC = gcc CXX = g++ DEFINES = -DQT_WEBKIT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED CFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. LINK = g++ LFLAGS = -Wl,-O1 LIBS = $(SUBLIBS) -L/usr/lib -lQtGui -lQtCore -lpthread -lmatheval AR = ar cqs RANLIB =
jetzt habe ich -lmatheval.o und auch -l matheval.o in makefile zugefügt aber der Linker findet die nicht:
test1: main.o g++ -o test1 -lmatheval.o main.o main.o:main.cpp g++ -c main.cpp clean: rm test1 main.o
#that's all
-
ich habe die library schöne in Qt-programm ohne Problem verwendet und habe nur
folgendes gemacht:
main.cpp#include <cassert> extern "C" { #include <matheval.h> } using namespace std; int main( int argc, char *argv[]) {
und in makefile habe ich sie mit den anderen qt-librarys den liker so übergegeben:
hier ist ein Abschnitt von Makefile:CC = gcc CXX = g++ DEFINES = -DQT_WEBKIT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED CFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) CXXFLAGS = -pipe -O2 -Wall -W -D_REENTRANT $(DEFINES) INCPATH = -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. LINK = g++ LFLAGS = -Wl,-O1 LIBS = $(SUBLIBS) -L/usr/lib -lQtGui -lQtCore -lpthread -lmatheval AR = ar cqs RANLIB =
jetzt habe ich -lmatheval.o und auch -l matheval.o in makefile zugefügt aber der Linker findet die nicht:
test1: main.o g++ -o test1 -lmatheval.o main.o main.o:main.cpp g++ -c main.cpp clean: rm test1 main.o
#that's all