0

What i'm trying to do is, basically, link one C++ File, to another. For example, first i have a cpp file, like, main. And I want to have a part where the user chooses something then the other cpp file opens.

4
Contributors
6
Replies
7
Views
9 Years
Discussion Span
Last Post by mitrmkar
0

How do you mean 'the other cpp file opens'?
Do you want function to be called from another CPP-file, or do you want the user to view the cpp-file's contents?

0

Just guessing here, but do you want main() to call a function that is another *.cpp file? For example,

// foo.cpp
#include <iostream>
int foo()
{
    std::cout << "Hello World\n";
    return 0;
}
// main.cpp
extern int foo();
int main()
{
    foo();
    return 0;
}

Now you have to compile main.cpp and foo.cpp then link the object files together to get a single executable program. Exactly how to do that depends on the compiler you are using because each one is different.

0

Yeah, Thats exactly what I want, but how do you link the object files together to make a single executable program? And when I tried making the two files, and putting the code on to them, it didn't work.

Thanx

0

Yeah, Thats exactly what I want, but how do you link the object files together to make a single executable program? And when I tried making the two files, and putting the code on to them, it didn't work.

Thanx

What compiler are you using?

0

The one in Dev-C++. (not sure what its called)

Well I take that you use the Dev-C++ IDE, so add the files to your project (create a new project, if you don't have one). Adding an existing file to project is done via Project/Add to Project menu. Once you have all required files you can build the project.

Here are some basic instructions ...
http://csjava.occ.cccd.edu/~gilberts/devcpp5/

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.