NI Home > Community > NI Discussion Forums

LabVIEW Embedded

Reply
Member
10Degree
Posts: 199
0 Kudos

Using LV C generator with Qt

Hi,

Not sure if this is the right board to post in but must be close.  I am evaluating the LabVIEW c code generator for use in porting a project to an embedded ARM platform.  We are going to use Qt for our embedded application and I am not able to get even a very simple c-generated VI to compile and run in Qt Creator.  I attached my generated code (just a VI that implements y = m * x + b).  Has anyone had any success in using LV generated C code in a Qt project?

Thanks

-cb

Member
10Degree
Posts: 199
0 Kudos

Re: Using LV C generator with Qt

I have some additional information to offer:

 

In my project, I am including the generated code by adding the source files to the Qt project in accordance with this document: http://zone.ni.com/reference/en-XX/help/373144B-01/lvcgenhelp/cgen_include_gen_code_ext_apps/

 

When I compile, I get this output:

 

Running build steps for project EvalLine_console...
Configuration unchanged, skipping qmake step.
Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe"
C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/_LVBuilds/LV_CCG/EvalLine_console'
gcc -c -g -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"..\..\..\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtCore" -I"..\..\..\QtSDK\Desktop\Qt\4.7.3\mingw\include" -I"." -I"evaluate_line_LV" -I"CCodeGen\libsrc\blockdiagram" -I"CCodeGen\libsrc\comms" -I"CCodeGen\libsrc\frontpanel" -I"CCodeGen\libsrc\os\common" -I"CCodeGen\libsrc\lvanalysis" -I"CCodeGen\include\blockdiagram" -I"CCodeGen\include\comms" -I"CCodeGen\include\frontpanel" -I"CCodeGen\include\platform\win-Qt" -I"CCodeGen\analysis\development\include" -I"CCodeGen\analysis\LV\source\include" -I"..\..\..\QtSDK\Desktop\Qt\4.7.3\mingw\include\ActiveQt" -I"debug" -I"..\..\..\QtSDK\Desktop\Qt\4.7.3\mingw\mkspecs\win32-g++" -o debug\Evaluate_line.o evaluate_line_LV\Evaluate_line.c
Makefile.Debug:354: warning: overriding commands for target `debug/Evaluate_line.o'
Makefile.Debug:292: warning: ignoring old commands for target `debug/Evaluate_line.o'
mingw32-make[1]: Leaving directory `C:/_LVBuilds/LV_CCG/EvalLine_console'
In file included from CCodeGen\include\blockdiagram/LVDefs.h:35,
from CCodeGen\include\blockdiagram/LVStringAndErrorCodes.h:15,
from CCodeGen\include\blockdiagram/LVCCG.h:22,
from CCodeGen\include\blockdiagram/LVCGenIncludes.h:18,
from evaluate_line_LV\Evaluate_line.c:19:
CCodeGen\include\platform\win-Qt/LVDefs_plat.h:37: error: redefinition of typedef 'float32'
CCodeGen\include\blockdiagram/LVDefs.h:17: note: previous declaration of 'float32' was here
CCodeGen\include\platform\win-Qt/LVDefs_plat.h:38: error: redefinition of typedef 'float64'
CCodeGen\include\blockdiagram/LVDefs.h:18: note: previous declaration of 'float64' was here
In file included from CCodeGen\include\blockdiagram/LVDefs.h:35,
from CCodeGen\include\blockdiagram/LVStringAndErrorCodes.h:15,
from CCodeGen\include\blockdiagram/LVCCG.h:22,
from CCodeGen\include\blockdiagram/LVCGenIncludes.h:18,
from evaluate_line_LV\Evaluate_line.c:19:
CCodeGen\include\platform\win-Qt/LVDefs_plat.h:86:1: warning: "isinf" redefined
In file included from CCodeGen\include\platform\win-Qt/LVSysIncludes.h:23,
from CCodeGen\include\blockdiagram/LVCGenIncludes.h:13,
from evaluate_line_LV\Evaluate_line.c:19:
c:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/../../../../include/math.h:371:1: warning: this is the location of the previous definition
In file included from CCodeGen\include\blockdiagram/LVDefs.h:35,
from CCodeGen\include\blockdiagram/LVStringAndErrorCodes.h:15,
from CCodeGen\include\blockdiagram/LVCCG.h:22,
from CCodeGen\include\blockdiagram/LVCGenIncludes.h:18,
from evaluate_line_LV\Evaluate_line.c:19:
CCodeGen\include\platform\win-Qt/LVDefs_plat.h:89:1: warning: "isnan" redefined
In file included from CCodeGen\include\platform\win-Qt/LVSysIncludes.h:23,
from CCodeGen\include\blockdiagram/LVCGenIncludes.h:13,
from evaluate_line_LV\Evaluate_line.c:19:
c:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/../../../../include/math.h:405:1: warning: this is the location of the previous definition
evaluate_line_LV\Evaluate_line.c: In function 'Evaluate_line_Run':
evaluate_line_LV\Evaluate_line.c:89: warning: unused variable 'nReady'
evaluate_line_LV\Evaluate_line.c:88: warning: unused variable 'bRunToFinish'
evaluate_line_LV\Evaluate_line.c: At top level:
evaluate_line_LV\Evaluate_line.c:109: warning: pointer targets in initialization differ in signedness
mingw32-make[1]: *** [debug/Evaluate_line.o] Error 1
mingw32-make: *** [debug] Error 2
The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project EvalLine_console (target: Desktop)
When executing build step 'Make'

 

Continued in next post...

Member
10Degree
Posts: 199
0 Kudos

Re: Using LV C generator with Qt

I did some poking around and found that if I include "extcode.h" in my .cpp, I can get around the "redefinition" errors. Now a compile yields this output and errors:

 

Running build steps for project EvalLine_console...
Configuration unchanged, skipping qmake step.
Starting: "C:\QtSDK\mingw\bin\mingw32-make.exe" 
C:/QtSDK/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `C:/_LVBuilds/LV_CCG/EvalLine_console'
g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"..\..\..\QtSDK\Desktop\Qt\4.7.3\mingw\include\QtCore" -I"..\..\..\QtSDK\Desktop\Qt\4.7.3\mingw\include" -I"." -I"evaluate_line_LV" -I"CCodeGen\libsrc\blockdiagram" -I"CCodeGen\libsrc\comms" -I"CCodeGen\libsrc\frontpanel" -I"CCodeGen\libsrc\os\common" -I"CCodeGen\libsrc\lvanalysis" -I"CCodeGen\include\blockdiagram" -I"CCodeGen\include\comms" -I"CCodeGen\include\frontpanel" -I"CCodeGen\include\platform\win-Qt" -I"CCodeGen\analysis\development\include" -I"CCodeGen\analysis\LV\source\include" -I"..\..\..\QtSDK\Desktop\Qt\4.7.3\mingw\include\ActiveQt" -I"debug" -I"..\..\..\QtSDK\Desktop\Qt\4.7.3\mingw\mkspecs\win32-g++" -o debug\main.o main.cpp
Makefile.Debug:357: warning: overriding commands for target `debug/Evaluate_line.o'
Makefile.Debug:295: warning: ignoring old commands for target `debug/Evaluate_line.o'
mingw32-make[1]: Leaving directory `C:/_LVBuilds/LV_CCG/EvalLine_console'
In file included from CCodeGen\analysis\LV\source\include/extcode.h:36,
from main.cpp:4:
CCodeGen\analysis\development\include/platdefines.h:122:4: error: #error "We don't know the Compiler"
CCodeGen\analysis\development\include/platdefines.h:137:4: error: #error "We don't know the ProcessorType architecture"
CCodeGen\analysis\development\include/platdefines.h:321:3: error: #error 
In file included from CCodeGen\analysis\LV\source\include/extcode.h:37,
from main.cpp:4:
CCodeGen\analysis\development\include/fundtypes.h:24: error: conflicting declaration 'typedef char int8_t'
c:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/../../../../include/stdint.h:27: error: 'int8_t' has a previous declaration as 'typedef signed char int8_t'
In file included from evaluate_line_LV/Evaluate_lineLib.h:4,
from main.cpp:25:
CCodeGen\include\platform\win-Qt/LVDefs_plat.h:24: error: conflicting declaration 'typedef signed char int8'
CCodeGen\analysis\development\include/fundtypes.h:157: error: 'int8' has a previous declaration as 'typedef char int8'
mingw32-make[1]: *** [debug/main.o] Error 1
mingw32-make: *** [debug] Error 2
The process "C:\QtSDK\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project EvalLine_console (target: Desktop)
When executing build step 'Make'

 

Has anyone ever gotten c-generated code to compile on Qt?
Thanks
-cb

Member
Matt.M
Posts: 90
0 Kudos

Re: Using LV C generator with Qt

[ Edited ]

Hello,

 

It looks like there are type definition conflicts.  I would look at the code referenced in these errors, and see if you can either remove one of them, or rename one, and replace all instances of it in the generated code.  This is not the best solution, since every time you generate code, you will have to find & replace for the type definitions that are conflicting.  

 

It looks like QT wants int8_t to be a signed char, but LabVIEW code gen wants int8_t to be a char. So you could try removing one of those definitions and see if the code runs correctly.  If it doesn't you will have to use the method I descibed above of renameing one of the typedefs and all instances that reference that particular typedef.

 

CCodeGen\analysis\development\include/fundtypes.h:24: error: conflicting declaration 'typedef char int8_t'
c:\qtsdk\mingw\bin\../lib/gcc/mingw32/4.4.0/../../../../include/stdint.h:27: error: 'int8_t' has a previous declaration as 'typedef signed char int8_t'
In file included from evaluate_line_LV/Evaluate_lineLib.h:4,
from main.cpp:25:
CCodeGen\include\platform\win-Qt/LVDefs_plat.h:24: error: conflicting declaration 'typedef signed char int8'
CCodeGen\analysis\development\include/fundtypes.h:157: error: 'int8' has a previous declaration as 'typedef char int8'

 

I have never heard of someone using the C Code generator to generate code for QT, but if you are compiling using a standards compliant compiler, the code should compile.

 

Regards,

Matt M.

Applications Engineer
National Instruments
Member
francoisC
Posts: 2
0 Kudos

Re: Using LV C generator with Qt

Hello,

 

Did you find any solution ? I am also trying to use a dll generated from labview in a C++/Qt software.

I have the same error :

In file included from ..\Test/extcode.h:14:0,

from ..\Test/SharedLib.h:1,

from main.cpp:5:

..\Test/platdefines.h:116:4: error: #error "We don't know the Compiler"

..\Test/platdefines.h:131:4: error: #error "We don't know the ProcessorType architecture"

..\Test/platdefines.h:308:3: error: #error


Could this be because I am using mingw compiler instead of msvc ?

 

Thx for your help.

François

Member
Zachmx
Posts: 179
0 Kudos

Re: Using LV C generator with Qt

It could be because of the compiler. You may want to try compiling a simple example program or try compiling your code in C++ first to make sure it is not a problem in the code.

Zach P.

Product Support Engineer | LabVIEW R&D | National Instruments
Member
10Degree
Posts: 199
0 Kudos

Re: Using LV C generator with Qt

francoisC,

I never found a solution so I gave up on the c code generator.  From my research in various online blogs etc, I came to the conclusion that it would be a lot of work to get this product to function correctly.  I expected an out of the box, quality drop-in solution for compiling my LabVIEW code to c for use in a project and I found that the product does not seem ready for prime time.

-10

Member
francoisC
Posts: 2

Re: Using LV C generator with Qt

Hello,

 

Thank you both for your answers.

My labview dll consisted only in a very simple calculus (sqrt(a²+b²)) and my C++/Qt program was only calling that function and displaying the result.

 

I think that the problem was about using mingw so in the platdefines.h file I added on line 115    

#elif defined(__GNUC__)
        #define Compiler    kGCC

 

On line 130 i added :

#elif Compiler == kGCC
	#define ProcessorType	kX86

By doing that the pragma errors vanished.

 

 

I also had trouble with typedef. I don't know exactly how but using this main.cpp with the include solved the problem.It had to do with the includes at the begining of the file. The definition of the FOO_FUNC was also needed.

 

#include <QtCore/QCoreApplication>
#include "SharedLib.h"
#include <QDebug>
#include "windows.h"

typedef double(* FOO_FUNC)(double , double);

int main(int argc, char *argv[])
{
    //QCoreApplication a(argc, argv);
    
    HMODULE dynamicLibrary_Handle = LoadLibrary( L"Sharedlib.dll");
        if( dynamicLibrary_Handle )
        {
            qDebug()<<"Successful in finding Sharedlib.dll" ;


            FOO_FUNC Proc =  (FOO_FUNC)GetProcAddress(dynamicLibrary_Handle,"Test");
            if(Proc == NULL)
            {
                 qDebug()<<"Failed in finding Test in Sharedlib.dll" ;
                 FreeLibrary(dynamicLibrary_Handle);
            }
            else
            {
                 qDebug() << "Process address found at: " << Proc ;
                 double test  = Proc(2,3);
                 qDebug()<< test;
                 FreeLibrary(dynamicLibrary_Handle);

            }

        }
        else
        {
            int lastError = GetLastError();
          qDebug()<<"Failed in finding Sharedlib.dll" ;
        }

        qDebug()<<"avent a.exec()";
    //return a.exec();
    qDebug()<<"apres a.exec()";
}

 

Moreover I had to suppress the app.exec because after the calculus the software was stuck and did not exit correctly. Because of this it might be difficult to use it with full potential in Qt application. However by calling through a QProcess should be ok.

 

With that I could make it run both with Qt4.8.1/msvc2010 and Qt4.8.3/mingw.

 

Another point is not to link with the .lib file of the library. Here is my .pro (i added directly all the labview .h files such as extcode.h etc... in my main.cpp directory, that is not clean but for a first try...)

#-------------------------------------------------
#
# Project created by QtCreator 2013-02-06T16:36:20
#
#-------------------------------------------------

QT       += core

QT       -= gui

TARGET = Test
CONFIG   += console
CONFIG   -= app_bundle


TEMPLATE = app


SOURCES += main.cpp

 

I am now trying to do it with a more complicated library to check if my modification on the platdefines.h still works.

 

Hope this might help.