I've been browsing the forums, and I've found a few posts that seem to address the same problem I'm having, but after implementing the solutions for those people, I still have problems.
I am trying to create a static library with one .pro file, and then use that library in another .pro file.
I created an example project to see if I could get it working. Here is the folder layout:
Example
--bin (Where the app and library build)
--LibraryProject
----LibraryProject // (contains LibraryProject.pro and all the header/source files)
----LibraryProject-build-desktop
--SampleProject
----SampleProject // (contains main.cpp hello world, would like to use the lib here)
----SampleProject-build-desktop
This is my LibraryProject.pro file
QT += core gui
TEMPLATE = lib
CONFIG += staticlib
HEADERS += \
SimpleClass.h
SOURCES += \
SimpleClass.cpp
TARGET = MyLibrary
DESTDIR = ../../bin/
QT += core gui
TEMPLATE = lib
CONFIG += staticlib
HEADERS += \
SimpleClass.h
SOURCES += \
SimpleClass.cpp
TARGET = MyLibrary
DESTDIR = ../../bin/
To copy to clipboard, switch view to plain text mode
This is the SimpleClass .h file (in the Library)
#ifndef SIMPLECLASS_H
#define SIMPLECLASS_H
class SimpleClass
{
public:
SimpleClass();
int ReturnNumber();
};
#endif // SIMPLECLASS_H
#ifndef SIMPLECLASS_H
#define SIMPLECLASS_H
class SimpleClass
{
public:
SimpleClass();
int ReturnNumber();
};
#endif // SIMPLECLASS_H
To copy to clipboard, switch view to plain text mode
This is the SimpleClass.cpp file (in the library)
#include "simpleclass.h"
SimpleClass::SimpleClass()
{
}
int SimpleClass::ReturnNumber()
{
return 0;
}
#include "simpleclass.h"
SimpleClass::SimpleClass()
{
}
int SimpleClass::ReturnNumber()
{
return 0;
}
To copy to clipboard, switch view to plain text mode
This is the SampleProject.pro file
LIBS += -L../../bin/ -lMyLibrary
INCLUDEPATH = ../../LibraryProject/LibraryProject
SOURCES += \
main.cpp
DESTDIR += ../../bin
LIBS += -L../../bin/ -lMyLibrary
INCLUDEPATH = ../../LibraryProject/LibraryProject
SOURCES += \
main.cpp
DESTDIR += ../../bin
To copy to clipboard, switch view to plain text mode
This is the main.cpp (In the Sample project)
#include <iostream>
//How do I #include and use this library??
//My #includes yield no .h's or libraries
//that I made available to me... using
//them anyways causes "not found" errors.
using namespace std;
int main()
{
//Would love to use the library right here
//SampleClass...
return 0;
}
#include <iostream>
//How do I #include and use this library??
//My #includes yield no .h's or libraries
//that I made available to me... using
//them anyways causes "not found" errors.
using namespace std;
int main()
{
//Would love to use the library right here
//SampleClass...
return 0;
}
To copy to clipboard, switch view to plain text mode
It seems no matter how I try to include the library...
LIBS += -L../../bin/ -lMyLibrary
INCLUDEPATH += ../../LibraryProject/LibraryProject/
or...
LIBS += ../../bin/libMyLibrary.a
or
The horrible Right-Click "Add Library" huge block of text...
No matter what method I try, the library is not found in the main.cpp...
What am I doing wrong?
(Included on this post should be the very example I just described)
(Crap, it's actually the UPDATEDExample.zip, not the Example.zip... but where the heck is the DELETE Attachment????)
Bookmarks