LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Calling Multiple mains

is there way to call multiple main in a project.

 

 

Now dont get  me confuse. I do know how to go the header file route. I was just wondering if there is a new way of calling multiple mains.

 

 

 

basically i already have project open. but i want to include another project in the same workspace that has a main also.

 

 

but in the second project i want to call the function call in the first project.

 

is there a way to do it. i have already include the 2nd project in the workspace, but when i call it in the first project it saids undefined symbol 

 

reference in my c file.

0 Kudos
Message 1 of 38
(4,193 Views)

Darnell:

 

Function names need to be unique in any project, so you cannot call multiple main's.

 

The best way to call functions in one project from another is to have the project with the calling functions set to generate an executable, and the project with the called functions set to generate a DLL.  Search the CVI help for DLL.  There are a few good articles there on generating and debugging DLLs.

 

Another option is to have the functions you want to call in a separate .c file, not the .c with your main(), and include the called-function .c file in both projects.

 

Having multiple projects in a workspace does not give you access to the functions in both: it's just a convenient way in the CVI environment to switch between projects.  You need to include a .c, and/or .h, and possibly .lib files in a project where you want to call the functions.

Message Edited by Al S on 09-10-2009 01:38 PM
0 Kudos
Message 2 of 38
(4,186 Views)
so basically you saying that you cant call multiple mains, just take old route , which is make a header file. which is cool and what i normally do.
0 Kudos
Message 3 of 38
(4,179 Views)

In any case, you need more than a .h file.  If you are building an EXE and a DLL, your calling project (EXE) needs to include the DLL's .lib and export .h files.  If you are only building an EXE, you need to include the .c file(s) and the .h file(s) of the functions you want to call.  Remember that you need to have the called functions in a .c file separate from the main() in your second project.

 

If you're interested in DLLs, I'd suggest that you look at the sample DLL projects that ship with CVI and at the example I posted to one of your earlier questions here: http://forums.ni.com/ni/board/message?board.id=180&message.id=42707&query.id=1161309#M42707

0 Kudos
Message 4 of 38
(4,174 Views)

ok i got another question. im done with header file situation.

 

 

 my problem is trying to call it and then it gives me an error  do you know why

body { margin: 0 0 0 0; padding:0 0 0 0 } td,div { font-family:Tahoma;font-size:12pt;vertical-align:top } body { margin: 0 0 0 0; padding:0 0 0 0 } .transcript { background-color:#d2d2d2; } .messageBlock { margin-left:4px; margin-bottom:3px } .message { margin-left:100px; word-wrap:break-word; white-space:-moz-pre-wrap; _white-space:pre; } .messageCont { margin-left:100px; word-wrap:break-word; white-space:-moz-pre-wrap; _white-space:pre;} .other { color:#39577a;vertical-align:top;font-weight:bold;font-style:normal;float:left; width:95px; } .myself { color:#da8103;font-style:normal;font-weight:bold;font-style:normal;float:left; width:95px; } .otherCont { font-size:8px;text-align:right; color:#39577a;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .myselfCont { font-size:8px;text-align:right; color:#da8103;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .system { margin-left:4px; word-wrap:break-word;color:#da8103;font-style:normal;font-weight:normal; white-space:-moz-pre-wrap; _white-space:pre; } .showTimestamp { margin-right:3px; float:right; color:#999999;font-style:normal;font-weight:normal; } .other1 { color:#ac2000;vertical-align:top;font-weight:bold;font-style:normal;float:left; width:95px; } .otherCont1 { font-size:8px;text-align:right; color:#ac2000;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .other2 { color:#3c9fa8;vertical-align:top;font-weight:bold;font-style:normal;float:left; width:95px; } .otherCont2 { font-size:8px;text-align:right; color:#3c9fa8;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .other3 { color:#e25614;vertical-align:top;font-weight:bold;font-style:normal;float:left; width:95px; } .otherCont3 { font-size:8px;text-align:right; color:#e25614;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .other4 { color:#0b6ac8;vertical-align:top;font-weight:bold;font-style:normal;float:left; width:95px; } .otherCont4 { font-size:8px;text-align:right; color:#0b6ac8;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .other5 { color:#b23290;vertical-align:top;font-weight:bold;font-style:normal;float:left; width:95px; } .otherCont5 { font-size:8px;text-align:right; color:#b23290;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .other6 { color:#02e7c7;vertical-align:top;font-weight:bold;font-style:normal;float:left; width:95px; } .otherCont6 { font-size:8px;text-align:right; color:#02e7c7;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .other7 { color:#5b3284;vertical-align:top;font-weight:bold;font-style:normal;float:left; width:95px; } .otherCont7 { font-size:8px;text-align:right; color:#5b3284;font-family:Arial,Lucida Grande;font-style:normal;vertical-align:top;font-weight:bold;float:left; width:95px; } .tsDisplay { display:block }



//***Header file
extern "C" FUNCTIONLIBRARY_API long f_ConvDblToSingleArray
(
double* double_array[4][1000],
double* single_array[3000] ,
int max_index );

//Library Function...(This compiles...)
extern "C" FUNCTIONLIBRARY_API long f_ConvDblToSingleArray
(
double* double_array[4][1000],
double* single_array[3000] ,
int max_index )
{
long error = F_SUCCESS;

int idx1 = 0;
int idx2 = 0;
int index = 0;

for (idx1=0; idx1 < max_index; idx1++)
{
for ( idx2=0; idx2 < max_index; idx2++ )
{
single_array[index++] = double_array[idx1][idx2];
}
}//

//****************calling program:************************
long q,u;
double temp_data[4][3000] =
{
0.0
};
double meas[3000] =
{
0.0
};

>>>>>>>>>Call to libray function from x program...
q=4;
u=1000;

CHK(f_ConvDblToSingleArray( &temp_data[q][u],
&meas[3000] ,
q ));

>>>>>>>>This call produces the following error:

error C2664: 'f_ConvDblToSingleArray' : cannot convert parameter 1 from 'double *' to 'double *[][1000]'
 

0 Kudos
Message 5 of 38
(4,157 Views)

ok i got another question. im done with header file situation.

 

 

 my problem is trying to call it and then it gives me an error  do you know why pertainingto the last post i sent

0 Kudos
Message 6 of 38
(4,155 Views)

Darnell:

 

Thanks for including the error message in your post.  That's helpful to us, but it should be helpful to you as well.

 

In your prototype for your function, you said that the first parameter is a multi-dimensional array of pointers.  When you called the function, you didn't pass the pointer to an array: you passed the pointer to one element.

 

So you got the error because the compiler couldn't convert the datatype you were trying to pass to the datatype you told the compiler to expect.

 

cannot convert parameter 1 from 'double *' to 'double *[][1000]'

 

Go to your C reference book or textbook, and read the section on passing array to functions.

 

Do you understand why you are declaring an array of pointers instead of an array of doubles?

0 Kudos
Message 7 of 38
(4,148 Views)

i tried everything,

 

(f_ConvDblToSingleArray( &temp_data,
&meas[3000] ,
q ));

 

 

i tried it this way also

 

 

and i also tried it the book way also

0 Kudos
Message 8 of 38
(4,143 Views)

Darnell:

 

I've responded before to your comments that you have "tried everything".  When it comes to posts on this forum, I'd suggest that you just take those words out of your vocabulary.  They just get in the way of you getting help here.

 

Let's look at this statement:

 

f_ConvDblToSingleArray( &temp_data, &meas[3000] , q )

 

In your calling routine, you declared temp_data as a multi-dimensional array of doubles.

In your function prototype, you declared double_array as a multi-dimensional array of pointers to doubles.

 

&temp_data is a pointer to the array of doubles, not an array of pointers to doubles.

 

In your calling routine, you declared meas as an array of doubles.

In your function prototype, you declared single_array as an array of pointers to doubles.

 

&meas[3000] is a pointer to a double (one single element of the array), not an array of pointers to doubles.

 

What is the "book way"?  What book are you using?  Please post the title and author of your book and the reference of how to pass arrays.

 

On to other comments.  What are you trying to do with the following statements?

 

    double temp_data[4][3000] = { 0.0 };


    double meas[3000] = { 0.0 };

 

Do you realize that you are only setting the first element of each array and not the entire array?

Here's what I consider the bigger picture.  I was giving you a hint when I asked why your function was using arrays of pointers.  Sometimes you need the flexibility you get by using arrays of pointers, but for your simple function, I would suggest using arrays of doubles, not arrays of pointers.

 

So here's your new function prototype:

 

long f_ConvDblToSingleArray ( double double_array[4][1000], double single_array[3000] , int max_index );

 

Here's your call to that function:

 

f_ConvDblToSingleArray( temp_data, meas, q );

 

To simplify these statements for the purposes of demonstration, I removed your "extern" declaration and the CHK() function.

 

Arrays and pointers are some of the fundamental concepts not only of C, but also of C++ (which you have told us is the language you are more familiar with).

 

In any strictly typed language, the parameter type you pass must be the same type the function expects.  C and C++ can do some automatic casting (conversion of datatypes), but converting from pointers to doubles isn't something that you should expect any compiler to do.

 

You need to get a good understanding of these concepts or you will continue to get lost.

0 Kudos
Message 9 of 38
(4,139 Views)
any suggestions im still coming up with same error
0 Kudos
Message 10 of 38
(4,137 Views)