LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Question: how to make .cpp file work with CIN?

Hi,

Compiling a CIN with VC++ 6.0, I'm trying to use extension .cpp instead of
..c. It's interesting .c file works but .cpp doesn't work with the same
project settings except the different extension.

Error message:

>Compiling...
>try.cpp
>Linking...
> Creating library Debug/try.lib and object Debug/try.exp
>cin.obj : error LNK2001: unresolved external symbol _CINRun
>Debug/try.dll : fatal error LNK1120: 1 unresolved externals
>Error executing link.exe.

Appreciate your help in advance.

Chen
0 Kudos
Message 1 of 6
(3,590 Views)
CIN's don't support C++ code, just C code. The cpp extension is for C++ files. When you are compiling, in most compilers, naming the code file .cpp tells the compiler to use the C++ compiler and .c tells the compiler to use the C compiler. Your error is resulting because you are using the C++ compiler.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 6
(3,590 Views)
You can use *.cpp files and LabView supports C++ as well. Rename the
generated *.c file into *.cpp and include this file in your VC++ project.
Declare your function in a Header-file (*.h) separately and describe the
interface as extern "C"

#ifdef __cplusplus
extern "C" {
#endif

CIN MgErr CINRun(int32 *hWnd);

#ifdef __cplusplus
}
#endif

Mareike


"Chemo Chen" wrote in message
news:a5e9c0$9dt$1@boss.cs.ohiou.edu...
> Hi,
>
> Compiling a CIN with VC++ 6.0, I'm trying to use extension .cpp instead
of
> .c. It's interesting .c file works but .cpp doesn't work with the same
> project settings except the different extension.
>
> Error message:
>
> >Compiling...
> >try.cpp
> >Linking...
> > Creating library Debug/try.lib and object Debug/try.exp

> >cin.obj : error LNK2001: unresolved external symbol _CINRun
> >Debug/try.dll : fatal error LNK1120: 1 unresolved externals
> >Error executing link.exe.
>
> Appreciate your help in advance.
>
> Chen
>
>
>
>
>
>
>
0 Kudos
Message 3 of 6
(3,590 Views)
Hi,
I'm encountering the same method and I tried the above method but it doesn't seem to work.  Could someone explain the part about .cpp vs. .c files again?
Also, Chemo, did you manage to find a solution to your problem?
Thanks!

0 Kudos
Message 4 of 6
(3,190 Views)

In case anybody still wants this information:

 

If you're doing it in a C++ project/.cpp file, you must use BOTH extern "C" AND __cdecl to use the C calling convention:

 

extern "C" MgErr __cdecl CINRun (...)

 

Hope this helps.

Message 5 of 6
(3,024 Views)

Did you mean to do this?

 

 

#ifdef __cplusplus
extern "C" {
#endif

CIN MgErr __cdecl CINRun(int32 *hWnd);

#ifdef __cplusplus
}
#endif

0 Kudos
Message 6 of 6
(2,569 Views)