PDA

View Full Version : NCreport2 help?



triperzonak
14th June 2008, 03:49
here are my steps following the use guide:

i include the includes of ncreport2 to INCLUDEPATH = ../include

i add the ncreport2.lib as LIBS+= ..lib/ncreport2.lib

i include them to my project as

#include "../preview/ncreportpreviewwindow.h"
etc..

after these three procedure i have no errors but after i add this line to my project

NCReport *report = new NCReport();

i got "undefined reference to `NCReport::NCReport(QObject*)'"

what ya think bout my error?:confused:

jpn
14th June 2008, 08:14
I'm afraid the content of LIBS variable is not correct. For a reason or another the lib is not getting linked.

triperzonak
14th June 2008, 09:45
I'm afraid the content of LIBS variable is not correct. For a reason or another the lib is not getting linked.

i suspect that too but after i read the qt documentation about sharing/linking of library i only got LIBS+= .lib file..

i only include that line to my .pro file and build. (am i missing something)

i try changing the path of .lib then error in building the file which mean it is really looking for the .lib

ncreport2 only have includes (which are .h) and lib that have ncreport2.lib, ncreport2.dll and ncreport2.exp

tnx for reply

triperzonak
16th June 2008, 03:48
i found the problem..

it is in the .h in importing the dll

#ifdef Q_WS_WIN
# if defined(NCREPORT_EXPORT)
# define NCREPORT_LIB_API __declspec(dllexport)
# elif defined(NCREPORT_IMPORT)
# define NCREPORT_LIB_API __declspec(dllimport)
# else
# define NCREPORT_LIB_API
# endif
#else
# define NCREPORT_LIB_API
#endif

i think its else if

but after i change elif to else if i got this warning
ncreport.h:50:8: warning: extra tokens at end of #else directive
ncreport.h:51:1: warning: "NCREPORT_LIB_API" redefined

is it wrong to use "else if"?

jpujolf
16th June 2008, 08:53
Add this line to your .pro file :

DEFINES += NCREPORT_IMPORT

And test. I think this may solve your problem...

triperzonak
16th June 2008, 10:51
tnx for the reply.. quite close but still far..

DEFINES += NCREPORT_IMPORT

yes i think i do need that.. but still got errors..
"undefined reference to `_imp___ZN8NCReportC1EP7QObject'"

i think the problem is in ncreport2.lib..

I copied the file to my project .pro

then add

LIBS += ncreport2.lib ? is this right?

plus i also copied the dll to the same path where my project is? again.. is this right?

as i posted earlier there is an error in syntax in defining the import/export class


#ifdef Q_WS_WIN
# if defined(NCREPORT_EXPORT)
# define NCREPORT_LIB_API __declspec(dllexport)
# elif defined(NCREPORT_IMPORT)
# define NCREPORT_LIB_API __declspec(dllimport)
# else
# define NCREPORT_LIB_API
# endif
#else
# define NCREPORT_LIB_API
#endif

do i need to edit that and make it "else if"? but i think the next line after else will be ignore

plus this uses "__declspec(dllexport)" do i need to change that to "Q_DECL_EXPORT" and same with import?

in the ifdef Q_WS_WIN do i need to specify that im using WIN OS or it is automatically detected?

tnx

jpujolf
16th June 2008, 11:32
tnx for the reply.. quite close but still far..
"undefined reference to `_imp___ZN8NCReportC1EP7QObject'"


Simple : the library is not found at linking step. Check the syntax of LIBS part of .pro files ( documented here http://doc.trolltech.com/4.4/qmake-variable-reference.html#libs )



LIBS += ncreport2.lib ? is this right?


No, you have to put something like this :

LIBS += -L"/path/to/ncreport2.lib" -lncreport2

It must be enough. Test it...



plus i also copied the dll to the same path where my project is? again.. is this right?


At runtime, probably you will need it if the directory where resides the DLL is not in the PATH, as you're running windows.

At compile/link time you only have to set correct paths on the LIBS section and everything must compile and link.



as i posted earlier there is an error in syntax in defining the import/export class

do i need to edit that and make it "else if"? but i think the next line after else will be ignore

plus this uses "__declspec(dllexport)" do i need to change that to "Q_DECL_EXPORT" and same with import?


That line hasn't an error. #elif is a correct preprocessor reserved word. You don't have to touch nothing on header. Just make linker find the lib in the right place.



in the ifdef Q_WS_WIN do i need to specify that im using WIN OS or it is automatically detected?

tnx


Q_WS_WIN is defined by QT, don't worry about it...

I hope this will be useful for you.

triperzonak
17th June 2008, 02:43
i try your post but still got errors.. jpujolf



build/dialogimpl.o(.text+0xa14):dialogimpl.cpp: undefined reference to `_imp___ZN8NCReportC1EP7QObject'
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [bin\mync.exe] Error 1
C:\MinGW\bin\mingw32-make.exe: *** [release] Error 2
g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -mthreads -Wl -Wl,-subsystem,windows -o bin\mync.exe build/dialogimpl.o build/main.o build/moc_dialogimpl.o -L"c:\Qt\4.3.5\lib" -lmingw32 -lqtmain c:/lib/ncreport2.lib -lQtSql4 -lQtXml4 -lQtGui4 -lQtCore4

i add this line to my project.pro

INCLUDEPATH += "C:/Program Files/NCReport2/include"
LIBS += "C:/Program Files/NCReport2/lib/ncreport2.lib" or
-L"C:/Program Files/NCReport2/lib" -lncreport2 or -L"C:/Program Files/NCReport2/lib"
-lncreport2
DEFINES += NCREPORT_IMPORT

to my project.cpp i only include
#include <QSqlDatabase>
#include "C:/Program Files/NCReport2/include/ncreport.h"
#include "C:/Program Files/NCReport2/include/ncreportoutput.h"
#include "C:/Program Files/NCReport2/include/ncreportpreviewoutput.h"
#include "C:/Program Files/NCReport2/include/ncreportpreviewwindow.h"

then
NCReport *report =new NCReport(); (note: no other declaration of NCReport, is this ryt?)

then when i build it the error shows..

hayzzzzzzzzzzzzz..

jpujolf
17th June 2008, 07:13
INCLUDEPATH += "C:/Program Files/NCReport2/include"

#include "C:/Program Files/NCReport2/include/ncreport.h"
#include "C:/Program Files/NCReport2/include/ncreportoutput.h"
#include "C:/Program Files/NCReport2/include/ncreportpreviewoutput.h"
#include "C:/Program Files/NCReport2/include/ncreportpreviewwindow.h"


So no need for the complete path in includes, only :

#include <ncreport.h>
#include <ncreportoutput.h>
#include <ncreportpreviewoutput.h>
#include <ncreportpreviewwindow.h>



DEFINES += NCREPORT_IMPORT


That's right...



LIBS += "C:/Program Files/NCReport2/lib/ncreport2.lib" or
-L"C:/Program Files/NCReport2/lib" -lncreport2 or -L"C:/Program Files/NCReport2/lib"
-lncreport2


Put EXACTLY this :

LIBS += -L"C:\Program Files\NCReport2\lib" -lncreport2



Your compile output

g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -mthreads -Wl -Wl,-subsystem,windows -o bin\mync.exe build/dialogimpl.o build/main.o build/moc_dialogimpl.o -L"c:\Qt\4.3.5\lib" -lmingw32 -lqtmain c:/lib/ncreport2.lib -lQtSql4 -lQtXml4 -lQtGui4 -lQtCore4


That's wrong !! As shown in the error you sent, you haven't put the LIBS line I wrote, or you haven't make qmake to generate a correct Makefile...

The link output must be something like this :

g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -mthreads -Wl -Wl,-subsystem,windows -o bin\mync.exe build/dialogimpl.o build/main.o build/moc_dialogimpl.o -L"c:\Qt\4.3.5\lib" -L"C:\Program Files\NCReport2\lib" -lmingw32 -lqtmain -lncreport2 -lQtSql4 -lQtXml4 -lQtGui4 -lQtCore4

And again, take a look at qmake's / g++ documentation. I had initially the same problem and is well documented.

triperzonak
17th June 2008, 08:00
heres my .pro

TEMPLATE = app
QT = gui core sql xml
CONFIG += qt \
release \
warn_on \
thread \
no_lflags_merge \
dll \
console
DESTDIR = bin
OBJECTS_DIR = build
MOC_DIR = build
UI_DIR = build
TARGET = mync
FORMS = ui/dialog.ui
HEADERS += src/dialogimpl.h
SOURCES += src/dialogimpl.cpp src/main.cpp
INCLUDEPATH += "C:/Program Files/NCReport2/include"
DEFINES = NCREPORT_IMPORT
LIBS += -L "C:\Program Files\NCReport2\lib" -lncreport2


same error:

g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -Wl,-subsystem,console -mthreads -Wl -Wl,--out-implib,bin\libmync.a -o bin\mync.exe build/dialogimpl.o build/main.o build/moc_dialogimpl.o -L"c:\Qt\4.3.5\lib" -L "C:\Program Files\NCReport2\lib" -lncreport2 -lQtSql4 -lQtXml4 -lQtGui4 -lQtCore4
mingw32-make.exe[1]: Leaving directory `C:/mync2'
build/dialogimpl.o(.text+0xa14):dialogimpl.cpp: undefined reference to `_imp___ZN8NCReportC1EP7QObject'
collect2: ld returned 1 exit status
mingw32-make.exe[1]: *** [bin\mync.exe] Error 1
C:\MinGW\bin\mingw32-make.exe: *** [release] Error 2

if you notice i put -L<space>"<dir>" i cant do this -L"<dir>" (without space) same error

"-Lc:\Program Files\NCReport2\lib" -lncreport2

tnx for your time..:)

jpujolf
17th June 2008, 09:00
LIBS += -L "C:\Program Files\NCReport2\lib" -lncreport2

same error:

if you notice i put -L<space>"<dir>" i cant do this -L"<dir>" (without space) same error


Why you can't ? "-Lc:\Program Files\NCReport2\lib" is wrong, -L"<path>" is correct, -L MUST be outside of quotes...

On the other hand, I've downloaded the windows version for NCReport2 and installed on a windows machine ( I work on a Linux box :) ). I've been looking the documentation and I've found the origin of the error :windows package provides ONLY VC++ libraries. I was blind !! g++ libraries have a "<library_name>.a" naming convention

You have two options :

- Write Norbert Szabo ( the author ) and "suplicate" a g++ distribution ( if Qt Open is g++ based, it's a more logical option make a NCReport g++ based, I think )

- Generate yourself a g++ library ( ncreport2.a ). You've tro generate da def file from DLL, generate a .a file and link it against your program...

Here's a guide ( for a python library, but you only have to change library name and all may work ). Take a look at section 2

http://sebsauvage.net/python/mingw.html

It works ?

triperzonak
17th June 2008, 10:39
You have two options :

- Write Norbert Szabo ( the author ) and "suplicate" a g++ distribution ( if Qt Open is g++ based, it's a more logical option make a NCReport g++ based, I think )

- Generate yourself a g++ library ( ncreport2.a ). You've tro generate da def file from DLL, generate a .a file and link it against your program...
It works ?

nope.. i did build "ncreport2.a" and link it to my project but i guess is for python..

i still got the same error.. maybe ill try your first option but i think it will took more time..:(

jpujolf
17th June 2008, 10:49
Surely, You've made some error creating ncreport2.a file or haven't changed the .pro file properly.

What have you done exactly ? ( commands for creating the .a file & changes made to .pro file to point the correct library )

jpujolf
17th June 2008, 11:04
Surely, You've made some error creating ncreport2.a file or haven't changed the .pro file properly.

What have you done exactly ? ( commands for creating the .a file & changes made to .pro file to point the correct library )

triperzonak
17th June 2008, 12:38
Run : pexports ncreport2.dll > ncreport2.def
then

Run : dlltool --dllname ncreport2.dll --def ncreport2.def --output-lib ncreport2.a

then it generate ncreport2.a i copyed it and paste bedside my .pro

i add to LIBS+= ncreport2.a, (in ncreport1 it works but not in ncreport2..)

same error after build..

jpujolf
17th June 2008, 14:17
Run : pexports ncreport2.dll > ncreport2.def


OK


then

Run : dlltool --dllname ncreport2.dll --def ncreport2.def --output-lib ncreport2.a


OK too...



then it generate ncreport2.a i copyed it and paste bedside my .pro


Unnecessary, so ncreport2.a is generated at the same directory as DLL resides. No need to do it



i add to LIBS+= ncreport2.a, (in ncreport1 it works but not in ncreport2..)
same error after build..

Incorrect !!

You have to put EXACTLY this in your LIBS entry at .pro file :

LIBS += -L"<path-to-library>" -lncreport2

As explained in mingw documentation, -L option is for adding a path to the library search, and -l option is for adding libraries, without extension.

Where <path-to-library> is only the path, not the complete name, and -lncreport means "library name is ncreport.a"

Do you understand now what I'm trying to explain ?

triperzonak
17th June 2008, 15:23
i follow this from documentation:

unix:LIBS += -L/usr/local/lib -lmath
win32:LIBS += c:/mylibs/math.lib


im using windows so win32 is the right way to follow and it has note that says

Note: On Windows, specifying libraries with the -l option, as in the above example, will cause the library with the highest version number to be used; for example, libmath2.lib could potentially be used instead of libmathlib. To avoid this ambiguity, we recommend that you explicitly specify the library to be used by including the .lib file name suffix.

and last.. i already use it and works in ncreport1 it uses libncreport.a too but i successfully link it..:D

jpujolf
17th June 2008, 15:38
So, no more ideas from me :(

It works for me as I explained to you...

Perhaps you may ask Norbert Szabo to find an answer.

triperzonak
12th July 2008, 15:44
my problem is now solve..

tnx nocisoft for releasing MinGW version of the reporting tool..

http://www.nocisoft.com/?id=down