12-11-2008 06:08 AM
Hello All,
I am trying to compile a fully functional existing source code to a DLL so that I can integrate it with LabView (using Call Library Function Node).
This link provides all the info required http://decibel.ni.com/content/docs/DOC-1690
However, my problem is when I add extern "C" __declspec( dllexport ) ....... (as per above link) the code does not compile - gives me errors.
It compiles fine without the extern.....
I have simplified my code (hence very crude) to highlight the problem and attached it here. I would appreciate someone can tell me why I cannot compile it when I include extern "C"...
Thanks in advance.
#include "stdafx.h"
#include <vector>
#include <math.h>
using namespace std;
const double kPI = 3.14159265358979323846;
//extern "C" __declspec( dllexport ) vector<double> deconWave1();
vector<double> deconWave1(){
vector<double> originalData( 32, 0.0 ); vector<double> originalFrequencies;originalFrequencies.push_back( 0.3 * 2.0 * kPI / originalData.size() );
double originalAmplitudes[] = { 3.0 };
double originalPhases[] = { 0.0 }; for ( size_t i = 0; i < originalData.size(); i++ ){
originalData[ i ] = originalAmplitudes[ 0 ] * cos( originalFrequencies[ 0 ] * i + originalPhases[ 0 ] );
}
return originalData;}
12-11-2008 07:14 AM
extern "C" is a C++ extension; a plain ANSI C compiler (like CVI) won't know what it means. It tells a C++ compiler not to mangle the function names it puts into the dll. Third party header files normally have a test to avoid this error, but it is perfectly safe simply to delete it for CVI.
JR
12-11-2008 06:35 PM
Hello JR,
Thank you for the reply. I forgot to mention in my post that I use Microsoft Visual C++ 2008 Express as the compiler (not CVI).
Microsoft Visual C++ 2008 Express does not give any errors with extern "C"... when I used it with the NI example code given in http://decibel.ni.com/content/docs/DOC-1690
However, when using Microsoft Visual C++ 2008 Express as the compiler, extern "C"... gives errors for my listed code. (without extern "C" ... my code compiles well)
Any help to compile my code with extern "C" using Microsoft Visual C++ 2008 Express would be appreciated
Thanks in advance
12-11-2008 11:59 PM
12-12-2008 03:09 AM
completely offtopic, but worth noting: did you consider using a valarray for holding your data ? the <valarray> header defines a lot of mathematical function which applies to a whole array (including trigonometric functions), taking care of the loop to walk through the data. also, a valarray can be efficiently sliced, that is you can create an array which is a subset of another array without overhead.
the valarray class is one of least known container class, although it has many advantages over a vector for frequent and/or global data manipulation.