Solved

How to call function in another project?

Posted on 2006-07-20
5
190 Views
Last Modified: 2013-11-20
I need to combine two project to compile together, also one project may need to call few function from another project, is it possible, thanks.
0
Comment
Question by:turbot_yu
  • 3
5 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17151898
>>need to call few function from another project

Whats exact problem for grabbing appropriate header / src files from another project and use them in your current one ? You can add header,src files in the new project, include appropriate header file in current project and then use that particular function..

-MAHESH
0
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 300 total points
ID: 17151907
otherwise simple solution like following for just example :

/**************************** PROJ1 ************************************/

//*****main1.cpp******

#include <stdio.h>
#include "func_def.h"

void main()
{
fun();
}

/****** func_def.c ********/
void fun()
{
printf(".....");
}

/*************************** END OF PROJ1 ******************************/

If this project resides in : C:\Pro1
================================================== =========================

Now project 2:

/******************************* PROJ2 ********************************/
//******main1.cpp****

#include <stdio.h>
#include "..\pro1\func_def.h"   //include header file like this

void main()
{
fun();
}

/***************************** END OF PROJ2 ****************************/

Hope this helps
-MAHESH
0
 

Author Comment

by:turbot_yu
ID: 17152438
May I use namespace to solve it?
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 17152494
well but with namespace also you need header and class src files to be present in your project or path...namespace will be more useful if you have classes with same name and you want to use all in your project...above described method is simplest way to achieve this..all you need is to just add header and src file in your project..include header file in src file where you want to use particular function..

-MAHESH
0
 
LVL 44

Assisted Solution

by:AndyAinscow
AndyAinscow earned 200 total points
ID: 17159252
A standard way to allow multiple applications to use the same functions is to place the functions in a dll.
Create a third project, put the .cpp/.h files for the shared functions into that project (remove from the project they are currently in).
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 42
ORA-01403: no data found 43 101
Complete beginner needs help making a cron job 9 116
changeXy challenge 13 82
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question