Jump to content

Building an executable program?

Go to solution Solved by Adonis4000,

I found my answer. Anyone who is having the same problem just read this website.

It says how to compile and build an executable file using the terminal. It's pretty easy.

https://courses.cs.washington.edu/courses/cse326/02wi/unix/g++.html

 

So, I'm new to programming and I thought I'd start learning C++ in Ubuntu.

I'm using the book "Programming Principles and Practice using C++ Second Edition" to get started.

I want to use the Visual Studio Code to create my source files, compile them and build an executable program.

I managed to create the source file with my code and now I want to compile it and build the executable program to see if it actually works.

But how do I do that?!?! Any help will be highly appreciated :)

 

ps. The book isn't helping on this one since it talks about a previous version of Visual Studio Code.

Link to comment
Share on other sites

Link to post
Share on other sites

I believe the book describes Visual Studio, you're talking about Visual Studio Code.

Visual Studio Code is just an advanced text editor while Visual Studio is a IDE.

If you want to follow the book you'll have to run Windows and use Visual Studio (Community edition)

Desktop: Intel i9-10850K (R9 3900X died 😢 )| MSI Z490 Tomahawk | RTX 2080 (borrowed from work) - MSI GTX 1080 | 64GB 3600MHz CL16 memory | Corsair H100i (NF-F12 fans) | Samsung 970 EVO 512GB | Intel 665p 2TB | Samsung 830 256GB| 3TB HDD | Corsair 450D | Corsair RM550x | MG279Q

Laptop: Surface Pro 7 (i5, 16GB RAM, 256GB SSD)

Console: PlayStation 4 Pro

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, mathijs727 said:

I believe the book describes Visual Studio, you're talking about Visual Studio Code.

Visual Studio Code is just an advanced text editor while Visual Studio is a IDE.

If you want to follow the book you'll have to run Windows and use Visual Studio (Community edition)

I think you are right on this one about Visual Studio IDE and Visual Studio Code.

Is there a way though to compile and build an executable program in linux? (through another program perhaps?)

Or maybe another IDE I can use in linux?

 

Thanks a lot by the way! xD

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, Adonis4000 said:

I think you are right on this one about Visual Studio IDE and Visual Studio Code.

Is there a way though to compile and build an executable program in linux? (through another program perhaps?)

Or maybe another IDE I can use in linux?

 

Thanks a lot by the way! xD

According to https://code.visualstudio.com/docs/languages/cpp 

Quote

If you want to build your application from VS Code, you will need to generate a tasks.json file:

  • Open the Command Palette (Ctrl+Shift+P).
  • Select the Tasks: Configure Task Runner command and you will see a list of task runner templates.
  • Select Others to create a task which runs an external command.
  • Change the command to the command line expression you use to build your application (e.g. g++ -g main.cpp).
  • Add any required args (e.g. -g to build for debugging).
  • You can now build your application with (Ctrl+Shift+B)

You should now see a tasks.json file in your workspace .vscode folder that looks something like:


{
    "version": "0.1.0",
    "command": "g++",
    "isShellCommand": true,
    "showOutput": "always",
    "args": ["-g", "main.cpp"]
}

For more information on tasks, see Integrate with External Tools via Tasks.

But as mentioned before, you really should use an IDE to build and publish programs and code editors to edit code. For windows I'd suggest Visual Studio Community 2015. It's huge but worth the size. For Linux I'm not experienced enough to help you other than the climate seems to be that "Unix is the IDE". (just try and look for IDE for Linux and sooner rather than later you'll be reading that quote)

Link to comment
Share on other sites

Link to post
Share on other sites

26 minutes ago, Naeaes said:

According to https://code.visualstudio.com/docs/languages/cpp 

Quote

If you want to build your application from VS Code, you will need to generate a tasks.json file:

  • Open the Command Palette (Ctrl+Shift+P).
  • Select the Tasks: Configure Task Runner command and you will see a list of task runner templates.
  • Select Others to create a task which runs an external command.
  • Change the command to the command line expression you use to build your application (e.g. g++ -g main.cpp).
  • Add any required args (e.g. -g to build for debugging).
  • You can now build your application with (Ctrl+Shift+B)

You should now see a tasks.json file in your workspace .vscode folder that looks something like:



{
    "version": "0.1.0",
    "command": "g++",
    "isShellCommand": true,
    "showOutput": "always",
    "args": ["-g", "main.cpp"]
}

For more information on tasks, see Integrate with External Tools via Tasks.

But as mentioned before, you really should use an IDE to build and publish programs and code editors to edit code. For windows I'd suggest Visual Studio Community 2015. It's huge but worth the size. For Linux I'm not experienced enough to help you other than the climate seems to be that "Unix is the IDE". (just try and look for IDE for Linux and sooner rather than later you'll be reading that quote)

Thanks , but this method doesn't seem to be working, maybe I'm doing something wrong... I don't know.

If anyone knows please help me with this one

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, Adonis4000 said:

I found my answer. Anyone who is having the same problem just read this website.

It says how to compile and build an executable file using the terminal. It's pretty easy.

https://courses.cs.washington.edu/courses/cse326/02wi/unix/g++.html

 

When your program gets bigger this way of building will be a lot of work.

Try learning cmake, it can generate Unix Makefiles or project files for various IDE's.

Cmake is cross platform so with a bit of work you're programs can compile and run on both Linux, OS X and Windows, just dont use posix functions.

 

Their are multiple IDEs available for Linux.

I have experience with Clion and its pretty good, although there was a memory leak on my system.

Other examples are Code Blocks and Eclipse.

 

Desktop: Intel i9-10850K (R9 3900X died 😢 )| MSI Z490 Tomahawk | RTX 2080 (borrowed from work) - MSI GTX 1080 | 64GB 3600MHz CL16 memory | Corsair H100i (NF-F12 fans) | Samsung 970 EVO 512GB | Intel 665p 2TB | Samsung 830 256GB| 3TB HDD | Corsair 450D | Corsair RM550x | MG279Q

Laptop: Surface Pro 7 (i5, 16GB RAM, 256GB SSD)

Console: PlayStation 4 Pro

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, mathijs727 said:

When your program gets bigger this way of building will be a lot of work.

Try learning cmake, it can generate Unix Makefiles or project files for various IDE's.

Cmake is cross platform so with a bit of work you're programs can compile and run on both Linux, OS X and Windows, just dont use posix functions.

 

Their are multiple IDEs available for Linux.

I have experience with Clion and its pretty good, although there was a memory leak on my system.

Other examples are Code Blocks and Eclipse.

I'll take a look into it, thanks for the help :)

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×