Qt Creator + adding external libraries = " ld: symbol(s) not found for architecture x86_64 "
-
Hi all,
I just start working with Qt, and have problem. I were trying to find some post with similar issues but didint find any solution.
All is going about reading data and printing pdf from it. I decided to use:
-
Qt to make some friendly enviroment,
-
libxl - library to read .xls files (http://www.libxl.com) ,
-
pdflib - library to print .pdf files (http://www.pdflib.com) ,
After dowloading libxl library, i found an examples inside of package. One of them was addapted to Qt. I used it and it works good.
Files included in project:
.pro
@#-------------------------------------------------Project created by QtCreator 2011-07-21T09:01:37
#-------------------------------------------------
QT += core gui
QT += gui declarativeTARGET = qt-libxl
TEMPLATE = appSOURCES += main.cpp
mainwindow.cppHEADERS += mainwindow.h
FORMS += mainwindow.ui
win32 {
INCLUDEPATH = ../../../include_cpp LIBS += ../../../lib/libxl.lib QMAKE_POST_LINK +=$$quote(cmd /c copy /y ..\..\..\bin\libxl.dll .)
} else:macx {
INCLUDEPATH = ../../include_cpp LIBS += -framework LibXL LIBS += -framework IOKit QMAKE_LFLAGS += -F../../ QMAKE_POST_LINK +=$$quote(mkdir $${TARGET}.app/Contents/Frameworks;cp -R ../../LibXL.framework $${TARGET}.app/Contents/Frameworks/)
} else {
INCLUDEPATH = ../../include_cpp LIBS += ../../lib/libxl.so QMAKE_LFLAGS_DEBUG = "-Wl,-rpath,../../lib" QMAKE_LFLAGS_RELEASE = "-Wl,-rpath,../../lib"
}@
mainwindow.h
@#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();public slots:
void generateExcel();private:
Ui::MainWindow *ui;
};#endif // MAINWINDOW_H@
mainwindow.cpp
@#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QProcess>#include <stdio.h>
#include <stdlib.h>#ifdef _WIN32
#include <windows.h>
#endif#include "libxl.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::generateExcel()
{using namespace libxl; Book* book = xlCreateBook(); // use xlCreateXMLBook() for working with xlsx files Sheet* sheet = book->addSheet("Sheet1"); sheet->writeStr(2, 1, "Hello, World !"); sheet->writeNum(4, 1, 1000); sheet->writeNum(5, 1, 2000); Font* font = book->addFont(); font->setColor(COLOR_RED); font->setBold(true); Format* boldFormat = book->addFormat(); boldFormat->setFont(font); sheet->writeFormula(6, 1, "SUM(B5:B6)", boldFormat); Format* dateFormat = book->addFormat(); dateFormat->setNumFormat(NUMFORMAT_DATE); sheet->writeNum(8, 1, book->datePack(2011, 7, 20), dateFormat); sheet->setCol(1, 1, 12); book->save("report.xls"); book->release(); ui->pushButton->setText("Please wait..."); ui->pushButton->setEnabled(false);
#ifdef _WIN32
::ShellExecuteA(NULL, "open", "report.xls", NULL, NULL, SW_SHOW);
#elif APPLE
QProcess::execute("open report.xls");
#else
QProcess::execute("oocalc report.xls");
#endif
ui->pushButton->setText("Generate Excel Report"); ui->pushButton->setEnabled(true);
}@
main.cpp
@#include <QApplication>
#include "mainwindow.h"int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();return a.exec();
}@
and some mainwindow.ui which probably isnt important.
Next i try to add second library - pdflib. In this package were examples for c, cpp, c obj. Only in c example was folder /lib where was libpdf.a . I imported library to Qt project by right mouse clicking in .pro file and choosing add library -> appropriate options. Then to .pro file was added:
@
macx: LIBS += -L$$PWD/../../../bind/c/lib/ -lpdfINCLUDEPATH += $$PWD/../../../bind/c/include
DEPENDPATH += $$PWD/../../../bind/c/includemacx: PRE_TARGETDEPS += $$PWD/../../../bind/c/lib/libpdf.a@
Afterwards I added to mainwindow.cpp little bit of code to try if it works:
@
...
#include "pdflib.h"
...
void MainWindow::generateExcel()
{
...
PDF * p;
/* create a new PDFlib object */
if ((p = PDF_new()) == (PDF *) 0) {
// comment
}
...
}
...@Finally i tried to compile project but error occurred:
"symbol(s) not found for architecture x86_64"All output in next post.
Checked file libpdf.a in terminal and it returned:
@libpdf.a: Mach-O universal binary with 2 architectures
libpdf.a (for architecture i386): current ar archive random library
libpdf.a (for architecture x86_64): current ar archive random library
@I tried to change include in mainwindow.cpp to:
@extern "C" {
#include "pdflib.h"
}@
But didnt help.Adding to .pro file:
@
CONFIG += x86_64
@
changed nothing to.I tried include .h files from both (c, cpp) versions of library (pdflib) without importing it by Qt, but result was the same.
I attempted also using other libraries for making .pdf files (e.g. libharu) without success.
By reading other threads I learned that it is a linking program.More info:
Mac OSX 10.7.4
Qt 5.0.2
Qt Creator 2.7.0
libxl 3.4.1.4
pdflib 8.0.5If anything more will be needed just say.
Spend last 6 h while trying to find solution and fix this issue.
Thanks for any hints!
-
-
first part of output:
@19:45:01: Uruchamianie kroków budowania dla projektu qt-libxl...
19:45:01: Uruchamianie "/Users/bartoszglowacki/Qt5.0.2/5.0.2/clang_64/bin/qmake" /Users/bartoszglowacki/Desktop/libxl-3.4.1.4/examples/qt/qt-libxl.pro -r -spec macx-clang CONFIG+=x86_64
19:45:01: Proces "/Users/bartoszglowacki/Qt5.0.2/5.0.2/clang_64/bin/qmake" zakończył się normalnie.
19:45:01: Uruchamianie "/usr/bin/make" -llibpdf
/Users/bartoszglowacki/Qt5.0.2/5.0.2/clang_64/bin/uic ../qt/mainwindow.ui -o ui_mainwindow.h
clang++ -c -pipe -mmacosx-version-min=10.6 -O2 -Wall -W -fPIE -DQT_NO_DEBUG -DQT_DECLARATIVE_LIB -DQT_WIDGETS_LIB -DQT_SCRIPT_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../../../../Qt5.0.2/5.0.2/clang_64/mkspecs/macx-clang -I../qt -I../../include_cpp -I../../../bind/c/include -I../../../../Qt5.0.2/5.0.2/clang_64/include -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtDeclarative -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtDeclarative.framework/Versions/5/Headers -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtWidgets -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtWidgets.framework/Versions/5/Headers -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtScript -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtScript.framework/Versions/5/Headers -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtGui -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtGui.framework/Versions/5/Headers -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtCore -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtCore.framework/Versions/5/Headers -I. -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/System/Library/Frameworks/AGL.framework/Headers -I. -I. -o main.o ../qt/main.cpp
clang++ -c -pipe -mmacosx-version-min=10.6 -O2 -Wall -W -fPIE -DQT_NO_DEBUG -DQT_DECLARATIVE_LIB -DQT_WIDGETS_LIB -DQT_SCRIPT_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../../../../Qt5.0.2/5.0.2/clang_64/mkspecs/macx-clang -I../qt -I../../include_cpp -I../../../bind/c/include -I../../../../Qt5.0.2/5.0.2/clang_64/include -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtDeclarative -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtDeclarative.framework/Versions/5/Headers -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtWidgets -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtWidgets.framework/Versions/5/Headers -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtScript -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtScript.framework/Versions/5/Headers -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtGui -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtGui.framework/Versions/5/Headers -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtCore -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtCore.framework/Versions/5/Headers -I. -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/System/Library/Frameworks/AGL.framework/Headers -I. -I. -o mainwindow.o ../qt/mainwindow.cpp
../qt/mainwindow.cpp:86:9: warning: unused variable 'image' [-Wunused-variable]
int image;
^
../qt/mainwindow.cpp:84:17: warning: unused variable 'imagefile' [-Wunused-variable]
const char* imagefile = "nesrin.jpg";
^
../qt/mainwindow.cpp:85:17: warning: unused variable 'optlist' [-Wunused-variable]
const char* optlist;
^
../qt/mainwindow.cpp:81:17: warning: unused variable 'searchpath' [-Wunused-variable]
const char* searchpath = "../data";
^
4 warnings generated.
/Users/bartoszglowacki/Qt5.0.2/5.0.2/clang_64/bin/moc -DQT_NO_DEBUG -DQT_DECLARATIVE_LIB -DQT_WIDGETS_LIB -DQT_SCRIPT_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../../../../Qt5.0.2/5.0.2/clang_64/mkspecs/macx-clang -I../qt -I../../include_cpp -I../../../bind/c/include -I../../../../Qt5.0.2/5.0.2/clang_64/include -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtDeclarative -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtDeclarative.framework/Versions/5/Headers -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtWidgets -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtWidgets.framework/Versions/5/Headers -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtScript -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtScript.framework/Versions/5/Headers -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtGui -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtGui.framework/Versions/5/Headers -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtCore -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtCore.framework/Versions/5/Headers -I. -I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/System/Library/Frameworks/AGL.framework/Headers -I. -I. -D__APPLE__ -D__GNUC__=4 ../qt/mainwindow.h -o moc_mainwindow.cpp
clang++ -c -pipe -mmacosx-version-min=10.6 -O2 -Wall -W -fPIE -DQT_NO_DEBUG -DQT_DECLARATIVE_LIB -DQT_WIDGETS_LIB -DQT_SCRIPT_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../../../../Qt5.0.2/5.0.2/clang_64/mkspecs/macx-clang -I../qt -I../../include_cpp -I../../../bind/c/include -I../../../../Qt5.0.2/5.0.2/clang_64/include -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtDeclarative -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtDeclarative.framework/Versions/5/Headers -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtWidgets -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtWidgets.framework/Versions/5/Headers -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtScript -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtScript.framework/Versions/5/Headers -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtGui -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtGui.framework/Versions/5/Headers -I../../../../Qt5.0.2/5.0.2/clang_64/include/QtCore -I../../../../Qt5.0.2/5.0.2/clang_64/lib/QtCore.framework/Versions/5/Headers -I. -@ -
second part of output:
@
I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers -I/System/Library/Frameworks/AGL.framework/Headers -I. -I. -o moc_mainwindow.o moc_mainwindow.cpp
clang++ -headerpad_max_install_names -mmacosx-version-min=10.6 -F../../ -o qt-libxl.app/Contents/MacOS/qt-libxl main.o mainwindow.o moc_mainwindow.o -framework LibXL -framework IOKit -L/Users/bartoszglowacki/Desktop/libxl-3.4.1.4/examples/qt/../../../bind/c/lib/ -lpdf -F/Users/bartoszglowacki/Qt5.0.2/5.0.2/clang_64/lib -framework QtDeclarative -F/Users/bartoszglowacki/Qt5.0.2/5.0.2/clang_64/qtxmlpatterns/lib -F/Users/bartoszglowacki/Qt5.0.2/5.0.2/clang_64/qtbase/lib -F/Users/bartoszglowacki/Qt5.0.2/5.0.2/clang_64/qtscript/lib -framework QtXmlPatterns -framework QtNetwork -framework QtCore -framework QtWidgets -framework QtGui -framework QtSql -framework QtScript -framework OpenGL -framework AGL
ld: warning: directory not found for option '-F/Users/bartoszglowacki/Qt5.0.2/5.0.2/clang_64/qtxmlpatterns/lib'
ld: warning: directory not found for option '-F/Users/bartoszglowacki/Qt5.0.2/5.0.2/clang_64/qtbase/lib'
ld: warning: directory not found for option '-F/Users/bartoszglowacki/Qt5.0.2/5.0.2/clang_64/qtscript/lib'Undefined symbols for architecture x86_64:
"_ATSFontFindFromName", referenced from:
_fnt_get_hostfont in libpdf.a(ft_hostfont.o)
"_ATSFontFindFromPostScriptName", referenced from:
_fnt_get_hostfont in libpdf.a(ft_hostfont.o)
"_ATSFontGetFileReference", referenced from:
_pdf_open_LWFN_resource in libpdf.a(p_type1.o)
"_ATSFontGetFontFamilyResource", referenced from:
_fnt_get_hostfont in libpdf.a(ft_hostfont.o)
"_ATSFontGetTable", referenced from:
_fnt_get_hostfont in libpdf.a(ft_hostfont.o)
"_ATSFontGetTableDirectory", referenced from:
_fnt_get_hostfont in libpdf.a(ft_hostfont.o)
"_CFRelease", referenced from:
_fnt_get_hostfont in libpdf.a(ft_hostfont.o)
"_CFStringCreateWithCString", referenced from:
_fnt_get_hostfont in libpdf.a(ft_hostfont.o)
"_CTFontCreateWithQuickdrawInstance", referenced from:
_fnt_get_hostfont in libpdf.a(ft_hostfont.o)
"_CTFontGetPlatformFont", referenced from:
_fnt_get_hostfont in libpdf.a(ft_hostfont.o)
"_CloseResFile", referenced from:
_LWFN_data_fill in libpdf.a(p_type1.o)
_pdf_open_LWFN_resource in libpdf.a(p_type1.o)
"_Count1Resources", referenced from:
_LWFN_data_fill in libpdf.a(p_type1.o)
_pdf_open_LWFN_resource in libpdf.a(p_type1.o)
"_CurResFile", referenced from:
_LWFN_data_fill in libpdf.a(p_type1.o)
_pdf_open_LWFN_resource in libpdf.a(p_type1.o)
"_FSGetCatalogInfo", referenced from:
_FSPathMakeFSSpec in libpdf.a(pc_file.o)
_pdf_open_LWFN_resource in libpdf.a(p_type1.o)
"_FSOpenResFile", referenced from:
_LWFN_data_fill in libpdf.a(p_type1.o)
_pdf_open_LWFN_resource in libpdf.a(p_type1.o)
"_FSPathMakeRef", referenced from:
_FSPathMakeFSSpec in libpdf.a(pc_file.o)
_pdf_open_LWFN_resource in libpdf.a(p_type1.o)
"_Get1IndResource", referenced from:
_LWFN_data_fill in libpdf.a(p_type1.o)
"_GetHandleSize", referenced from:
_LWFN_data_fill in libpdf.a(p_type1.o)
"_HLock", referenced from:
_LWFN_data_fill in libpdf.a(p_type1.o)
"_HUnlock", referenced from:
_LWFN_data_fill in libpdf.a(p_type1.o)
"_ResError", referenced from:
_pdf_open_LWFN_resource in libpdf.a(p_type1.o)
"_UseResFile", referenced from:
_LWFN_data_fill in libpdf.a(p_type1.o)
_pdf_open_LWFN_resource in libpdf.a(p_type1.o)
"_kCFAllocatorDefault", referenced from:
_fnt_get_hostfont in libpdf.a(ft_hostfont.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [qt-libxl.app/Contents/MacOS/qt-libxl] Error 1
19:45:04: Proces "/usr/bin/make" zakończył się kodem wyjściowym 2.
Error while building/deploying project qt-libxl (kit: Desktop Qt 5.0.2 clang 64bit)
Podczas wykonywania kroku "Make"
19:45:04: Elapsed time: 00:03.@