How do I compile and link multiple files from the command line?

user4266621

I used to use visual studio as a compiler for C++. I have been recently using g++ in cygwin. My problem is I donot know how to use cygwin for inheritance. The code below is just for illustration, to make my question more clearer.

Base class:

// A.h:
class A{
void func1();
};
class B:A{
func2();
};

//-------------
//A.cpp:
#include"A.h";
A::func1(){
};
//-----------

//B.cpp:
#include"A.h";
B::func2(){
func1();
};

int main(){
B b.
b.func2();
return 0;}
//----------------

I run (similar to ) this without any problem in visual studio. But I do not know how to run it in cygwin. How to include A.h , A.cpp, to run main() in B.cpp.

vincent

You need to compile your class implementation files into object files first, then link them.

If you were to use the g++ compiler, you could run these commands...

  1. g++ -c A.cpp
  2. g++ -c B.cpp
  3. g++ A.o B.o main.cpp -o my_program

This can be automated with a Makefile, so you don't have to type everything out. As others have mentioned GDB can also be used for debugging, but you need to add the '-g' option to your compiler flags to created debugging symbols.

Also, you have a period at the end of line 1 of your main function, rather than a semi-colon.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I FTP multiple files from the command line?

From Dev

How do I easily rename multiple files using command line?

From Dev

How do I easily rename multiple files using command line?

From Dev

How do I zip up multiple files on command line?

From Dev

how can I print multiple odt files from the command line?

From Dev

How do I add multiple "+" commands into less from the command line

From Dev

How do I add multiple "+" commands into less from the command line

From Dev

How do I run a command on multiple files

From Dev

How to compile and link separated .h and .cpp files in C++ using the command line?

From Dev

How do I stop multiple line output from command substitution from being concatenated in BASH script?

From Dev

How do I convert .doc files to .txt using LibreOffice from the command line?

From Dev

How do I add files to a VLC playlist from the command line on OS X?

From Dev

How do I mount Nexus 7 to view files from command line

From Dev

How do I pass a command-line program a list of files from a directory?

From Dev

How do I move all files from one folder to a subfolder except .html file using the command line?

From Dev

From the command line, how do I zip specific files and directories into one compressed folder?

From Dev

How do I copy files from the source with different dates than the destination using the Command Line

From Dev

How to compile multiple proto files in single command?

From Dev

How do I start screen with multiple splits directly from the command line?

From Dev

How do I open a new command line window from an sh script and then pass in multiple commands

From Dev

How do I execute a command in an iTerm window from the command line?

From Dev

How do I pass a username to an FTP command from the command line?

From Dev

How do I upload files using the command line on Windows?

From Dev

How can I merge two CSV files from command line?

From Dev

How to I manage Azure "files" from GUI and command line?

From Dev

How do I edit previous lines in a multiple line command in Bash?

From Dev

How do i execute multiple commands sequentially on the command line?

From Dev

How do I scrape the link from an <a> string in one line?

From Dev

How do I detach from a controlling terminal from the command line?

Related Related

  1. 1

    How do I FTP multiple files from the command line?

  2. 2

    How do I easily rename multiple files using command line?

  3. 3

    How do I easily rename multiple files using command line?

  4. 4

    How do I zip up multiple files on command line?

  5. 5

    how can I print multiple odt files from the command line?

  6. 6

    How do I add multiple "+" commands into less from the command line

  7. 7

    How do I add multiple "+" commands into less from the command line

  8. 8

    How do I run a command on multiple files

  9. 9

    How to compile and link separated .h and .cpp files in C++ using the command line?

  10. 10

    How do I stop multiple line output from command substitution from being concatenated in BASH script?

  11. 11

    How do I convert .doc files to .txt using LibreOffice from the command line?

  12. 12

    How do I add files to a VLC playlist from the command line on OS X?

  13. 13

    How do I mount Nexus 7 to view files from command line

  14. 14

    How do I pass a command-line program a list of files from a directory?

  15. 15

    How do I move all files from one folder to a subfolder except .html file using the command line?

  16. 16

    From the command line, how do I zip specific files and directories into one compressed folder?

  17. 17

    How do I copy files from the source with different dates than the destination using the Command Line

  18. 18

    How to compile multiple proto files in single command?

  19. 19

    How do I start screen with multiple splits directly from the command line?

  20. 20

    How do I open a new command line window from an sh script and then pass in multiple commands

  21. 21

    How do I execute a command in an iTerm window from the command line?

  22. 22

    How do I pass a username to an FTP command from the command line?

  23. 23

    How do I upload files using the command line on Windows?

  24. 24

    How can I merge two CSV files from command line?

  25. 25

    How to I manage Azure "files" from GUI and command line?

  26. 26

    How do I edit previous lines in a multiple line command in Bash?

  27. 27

    How do i execute multiple commands sequentially on the command line?

  28. 28

    How do I scrape the link from an <a> string in one line?

  29. 29

    How do I detach from a controlling terminal from the command line?

HotTag

Archive