LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Linking to static library developed in VC++ from CVI

Hi,
I'm having a CVI 6.0 application where in i'm trying to link to a static library developed using VC++ 6.0.
I'm getting a link error as follows:
"An unspecified error has occured, probably due to corrupted data. Aborted load of member ".\..\RelayControl.obj" from library Relay.lib".

In my VC++ project, the actual implementation for the functions are done using C++ & STL. I have a class that does the actual tasks & from the function body, i'm making calls to this class using an instance of it.

The code looks something like this

/// RelayControl.hpp & RelayControl.cpp contains implementation of my class ///////

///// Relay.h - Shipped along with the static library //////////
extern "c" void func1();
//
/////////////////////////////////////

//// Relay.cpp /////////
#include "Relay.h"
#include "RelayControl.hpp"

void func1 ()
{
//Create an instance of RelayControl class
//Call some functions
}
///////////////////////////

Also I'm getting this error only when i have some C++ code in my function body. In func1(), if i just say return, i'm not getting this linker error.

Can anybody tell me what's the problem with this .

Your help will be greatly appreciated.
Thanks in advance.
0 Kudos
Message 1 of 6
(4,057 Views)
I noticed one thing, though I'm not sure that it solves your specific error case. It could be that you are compiling your OBJ in Visual C++ as C++ code, not as C code. In Visual C++, if you name a file with the CPP extension, it defaults to the C++ compiler. If you name a file with the C extension, it defaults to the C compiler. You should try renaming your relay.cpp file to relay.c or add extern "C" declarations for your functions.

Best Regards,

Chris Matthews
National Instruments
0 Kudos
Message 2 of 6
(4,057 Views)
Hi,

If i change my file name to .c, I won't be able to include 'RelayControl.hpp' into this file because, it won't recognize my class declarations. Also i have a these statements in my .hpp file, that forbids me from including this file in any non-c++ files.
#ifndef __cplusplus
#error ....
#endif

Is there a way to include my .hpp file in a .c file ?

Thanks,
swamy
0 Kudos
Message 3 of 6
(4,057 Views)
Hi,
from your description it seems that your VisualC Code is really C++. You
will not be able to compile this code with the VisualC C-compiler. From my
point of view there are two solutions:

1. Change the VisualC Code so that it can be compiled using the C-compiler
(remove classes and so on...)

2. Generate a DLL rather than an object in VisualC, exporting wrapper
C-Functions you can access from CVI. (I would prefer this solution.)

Regards
Torsten

"nswamys" schrieb im Newsbeitrag
news:506500000005000000EBCB0000-1042324653000@exchange.ni.com...
> Hi,
>
> If i change my file name to .c, I won't be able to include
> 'RelayControl.hpp' into this file because, it won't recognize my class
> declarations. Also i have a these statements
in my .hpp file, that
> forbids me from including this file in any non-c++ files.
> #ifndef __cplusplus
> #error ....
> #endif
>
> Is there a way to include my .hpp file in a .c file ?
>
> Thanks,
> swamy
0 Kudos
Message 4 of 6
(4,057 Views)
Torsten is correct. You won't be able to link the C++ files in CVI. The DLL is the best approach.

Chris
0 Kudos
Message 5 of 6
(4,057 Views)
Thanks a lot for your responses.

I have written a sample program which proves that we can use C++ in my VC static library. It works fine when i use just plain C++ & don't use any STL features in it. But when i use some of the STL features like map etc.. CVI fails to link to my VC static library.

Could anybody explain me why ? I appreciate if anybody can make the sample code work !!!! Too much to ask i think !!!!

I'm doubting that it could be a problem with CVi linker or with VC++ compiler.

The code is attached below.
Note the following:
1. When you build the static library and build the CVi application as it is you will get liker errors saying unresolved symbols. This error is different from what i'm getting in m
y actual project.
2. If you comment out all the STL code i.e
a. #include & relayMap variable declaration incliding typedef, in VcClass.hpp
b. for loop part of test1::func3()

and then rebuild the projects, it will be successful.
0 Kudos
Message 6 of 6
(4,057 Views)