g16bit
29th April 2011, 11:58
My purpose is to create and use a very simple static library. I have successful in building library (both .a and .so). The problem is I dont know how to use a function from my lib just like the way QString do: QString::number(2); for example. So I post my code here and the ways I've tried:
mylib.h
#ifndef MYLIB_H
#define MYLIB_H
class mylib
{
public:
//De/Construct function
mylib();
~mylib();
//Add function
inline int add(int a, int b) const;
};
#endif
file mylib.cpp
#include"mylib.h"
#include<QString>
#include<QDebug>
mylib::mylib() {}
mylib::~mylib() {}
inline int mylib::add(int a, int b) const
{
qDebug().operator <<("LCommon::Currently in int add(int, int) const function.");
return a+b;
}
from 2 files above I compiled and got file libmylib.a
Now I want to use add function so I make a simple project like this:
file use1.pro
QT += core gui
TARGET = use1
TEMPLATE = app
LIBS += $$(CPPLIBS)/libmylib.a
INCLUDEPATH += $$(CPPLIBS)/libinclude #contain header file here
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
and in the main function of the mainwindow.cpp file
int a = mylib::add(6,7);
and it give errors:
/mainwindow.cpp:13: error: undefined reference to `mylib::add(int, int) const'
I've find about 5-6 post in this forum about using library in Qt and still dont get any solution for this. Im a newbie here so please help me. Thanks alot.
Added after 7 minutes:
In Addition, I've already include mylib.h file in mainwindow.h.
mylib.h
#ifndef MYLIB_H
#define MYLIB_H
class mylib
{
public:
//De/Construct function
mylib();
~mylib();
//Add function
inline int add(int a, int b) const;
};
#endif
file mylib.cpp
#include"mylib.h"
#include<QString>
#include<QDebug>
mylib::mylib() {}
mylib::~mylib() {}
inline int mylib::add(int a, int b) const
{
qDebug().operator <<("LCommon::Currently in int add(int, int) const function.");
return a+b;
}
from 2 files above I compiled and got file libmylib.a
Now I want to use add function so I make a simple project like this:
file use1.pro
QT += core gui
TARGET = use1
TEMPLATE = app
LIBS += $$(CPPLIBS)/libmylib.a
INCLUDEPATH += $$(CPPLIBS)/libinclude #contain header file here
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
and in the main function of the mainwindow.cpp file
int a = mylib::add(6,7);
and it give errors:
/mainwindow.cpp:13: error: undefined reference to `mylib::add(int, int) const'
I've find about 5-6 post in this forum about using library in Qt and still dont get any solution for this. Im a newbie here so please help me. Thanks alot.
Added after 7 minutes:
In Addition, I've already include mylib.h file in mainwindow.h.