Configuring Netbeans for C++ code with options - c++

I can compile a C++ code from ubuntu terminal with lapack library as
$g++ -lstdc++ -o fast_solver fast_solver.cpp -llapack
My question is if I want to use Netbeans IDE to compile the same code how do I configure Netbeans? More specifically, how do I ask Netbeans to compile with -lstdc++ and -llapack options?
Thank you in advance.
Best,
Geek

All you need (including compilers) comes in that NetBeans IDE package.
I would suggest that you read this guide which will show you how to create a new project and run code.
Its pretty easy.
In NetBeans IDE press F1 for more documentation.

Related

Using GTK+ without MSYS2

Dear programmers and developers,
I really want to try out GTK+ 3 on windows. Therefore, I read the official GTK+ download explanations at https://www.gtk.org/download/windows.php and installed everything with MSYS2.
Now I have a lot of files in my mingw64 subdirectory of my MSYS2 folder.
The question: How do I include all of them right? How do I link to GTK+ with all it's dependencies? I know there is a magic pkg-config attribute for the Linux C/C++ compiler, but unfortunately I am really not interested in compiling my projects in MSYS2. I am willing to use a simple MinGW (64) compiler.
Can anybody help me using the .a's, .h's and .dll'a that MSYS2 generated with a simple MinGW 64bit compiler for a stupid C++ project?
It would make me extremely happy!
Darth Moon
€edit: I actually have downloaded a precompiled GTK+ version from https://www.dropbox.com/sh/8d1qbh5dsp044on/AAB63l5I1eZks-QqjH6HXUJHa. Unfortunately, it is only 32bit but I will soon try to compile the whole GTK+ project on myself like this guy at https://github.com/Wesley-Chan/GTK-for-Windows did.
But if anybody has any idea how to build GTK+ in a smooth way under windows (especially for 64bit), please let me know! I really enjoyed the GTK+ example application and I really want to make my own ones!
I was able to successfully compile a GTK3 program in a MinGW 64-bit shell from MSYS2. First I installed the GTK3 package:
pacman -S $MINGW_PACKAGE_PREFIX-gtk3
Then I compiled the first example program from this page using the following command:
gcc test_gtk.c $(pkg-config gtk+-3.0 --cflags --libs)
Then I ran ./a.exe and it created a window.
If you are getting "undefined reference" linker errors, it means your Makefile is not linking your program to all of the correct libraries, or the order of the inputs to the linker is wrong.

How to know the command line arugments to build a project that was coded in eclipse

I have a project that I coded in Eclipse, now I need to compile it and run using the terminal. The project has some additional libraries that were added to the linker.
e.g.
g++ then what?
How can I know that command line arguments that I need to run it through the terminal?
The project was coded in c++ using eclipse Luna on a linux machine.
Thanks
You could always try
g++ -std=c++0x your_file_name.cpp -o desired_output_name

Run C++ in command prompt - Windows

I know that everyone uses an IDE nowadays, but I just find it simpler to write my code in notepad++, compile it using a command prompt command, and run it from there too. At least that works for Java and Python. I've tried to get my head around how to do that with C++, and haven't been able to find anything good. Is there any compiler (like Java's JDK) that I can stick into my path and use the C++ equivalent of javac and java to run and compile my code from CMD?
Note: please don't post answers and comments about how IDEs are better - I know they are. I'm just used to doing it the old way :D
Steps to perform the task:
First, download and install the compiler.
Then, type the C/C++ program and save it.
Then, open the command line and change directory to the particular one where the source file is stored, using cd like so:
cd C:\Documents and Settings\...
Then, to compile, type in the command prompt:
gcc sourcefile_name.c -o outputfile.exe
Finally, to run the code, type:
outputfile.exe
If you're running Windows then make use of this:
g++ -o program program.cpp
g++ is the name of the compiler and -o is the option needed for creating a .o file. Program (without .cpp suffix) is the exe file and program.cpp is your source file that you want to compile.
g++ -o program program.cpp&program.exe
Use this shortcut to run the .exe file of the program. This might run in Linux but you may have to use .out suffix instead of .exe. Use this handy batch script to execute your programs on Windows:
#echo off&&cls
set /p pathName=Enter The Path where the file is located:%=%
cd %pathName%
REM set /p exec=Enter The Name of the executable you want to make:%=%
set /p file=Enter The Name of the file you want to compile:%=%
g++ -o %file% %file%.cpp
%file%.exe
save it as cppExecutor.bat
Also you could use the following commands on Unix (Linux and Mac) OS:
CC program.cc
If you want to use gcc:
gcc -o program program.cpp
With the shortcut:
gcc -o program program.cpp&program.exe
It depends on what compiler you're using.
For example, if you are using Visual C++ .NET 2010 Express, run Visual C++ 2010 Express Command Prompt from the start menu, and you can simply compile and run the code.
> cl /EHsc mycode.cpp
> mycode.exe
or from the regular command line, you can run vcvars32.bat first to set up the environment. Alternatively search for setvcvars.cmd (part of a FLOSS project) and use that to even locate the installed VS and have it call vcvars32.bat for you.
Please check your compiler's manual for command lines.
Sure, it's how most compilers got started. GCC is probably the most popular (comes with most flavors of *nix). Syntax is just gcc my_source_code.cpp, or gcc -o my_executable.exe my_source_code.cpp. It gets more complicated, of course, when you have multiple source files (as in implementation; anything #included works automatically as long as GCC can find it).
MinGW appears to be a version of GCC for Windows, if that's what you're using. I haven't tried it though.
Pretty sure most IDEs also include a command line interface. I know Visual Studio does, though I have never used it.
I really don't see what your problem is, the question is rather unspecific. Given Notepad++ I assume you use Windows.
You have so many options here, from the MinGW (using the GCC tool chain and GNU make) to using a modern MSVC. You can use the WDK (ddkbuild.bat/.cmd or plain build.exe), the Windows SDK (nmake.exe), other tools such as premake and CMake, or msbuild that comes with MSVC and the Windows SDK.
I mean the compiler names will differ, cl.exe for MSVC and the WDK and Windows SDK, gcc.exe for MinGW, but even from the console it is customary to organize your project in some way. This is what make and friends were invented for after all.
So to know the command line switches of your particular compiler consult the manual of that very compiler. To find ways to automate your build (i.e. the ability to run a simple command instead of a complex command line), you could sift through the list on Wikipedia or pick one of the tools I mentioned above and go with that.
Side-note: it isn't necessary to ask people not to mention IDEs. Most professional developers have automated their builds to run from a command line and not from within the IDE (as during the development cycle for example), because there are so many advantages to that approach.
Download MinGW form : https://sourceforge.net/projects/mingw-w64/
use notepad++ to write the C++ source code.
using command line change the directory/folder where the source code is saved(using notepad++)
compile: g++ file_name.cpp -o file_name.exe
run the executable: file_name.exe
first Command is :
g++ -o program file_name.cpp
Second command is :
.\program.exe
Let us Check this image
A better alternative to MinGW is bash for powershell. You can install bash for Windows 10 using the steps given here
After you've installed bash, all you've got to do is run the bash command on your terminal.
PS F:\cpp> bash
user#HP:/mnt/f/cpp$ g++ program.cpp -o program
user#HP:/mnt/f/cpp$ ./program
This is what I used on MAC.
Use your preferred compiler.
Compile with gcc.
gcc -lstdc++ filename.cpp -o outputName
Or Compile with clang.
clang++ filename.cpp -o outputName
After done compiling. You can run it with.
./outputFile
Open cmd and go In Directory where file is saved. Then,
For compile,
g++ FileName. cpp
Or
gcc FileName. cpp
For Run,
FileName. exe
This Is For Compile & Run Program.
Make sure, gcc compiler installed in PC or Laptop.
And also path variable must be set.
have MinGW compiler bin directory added to path.
use mingw32-g++ -s -c source_file_name.cpp -o output_file_name.o to compile
then mingw32-g++ -o executable_file_name.exe output_file_name.o to build exe
finally, you run with executable_file_name.exe
[Working 100%] from a Windows user.
Open the terminal(powershell) where your file.cpp is created.
g++ file.cpp //it will compile the file into a.exe
.\a.exe //this will run the program.
There are few ways:
Using GNU Compiler Collection (GCC):
gcc -lstdc++ filename.cpp -o outputName
Using g++ command:
g++ -o outputName filename.cpp
Using clang++:
clang++ filename.cpp -o outputName
You can run your code by just typing
To Compile
g++ file_name.cpp
To Run:
a
only this you have to do to run c++ code in cmd which is written in notepad++
enter image description here
enter image description here

Setting up ccache with Qt Creator on Windows

I'm trying to set up ccache in Qt Creator on Windows.
Unfortunatelly I couldn't find any good instruction. How to make it working?
I have ccache installed with Cygwin.
edit:
I've tried adding
QMAKE_CXX+="ccache g++"
as additional parameter in qmake build step.
But in compile output I still have "g++ -c -g -Wall ..." and I suppose it should be "ccache g++ ..."
It should be:
"QMAKE_CXX=ccache g++"
And you might need to rerun qmake from the Build menu if QtCreator doesn't update automatically the makefile after you add that parameter.
QtCreator doesn't know about ccache, and besides, it's looking for trouble to mix Cygwin binaries with native binaries on Windows.

Compiling a Win32 GUI app (without a console) using MinGW and Eclipse

I'm using the eclipse IDE with MinGW as my compiler, to make a Win32 GUI app.
I want to get rid of the console, but compiling the program with -mwindows option has no effect and the console is still there.
Using the -Wl,--subsystem,windows flag also produces no effect. What am I doing wrong ?
For gcc on Windows, two things should be considered to build a non-console Windows app:
Compiler option -mwindows
Have WinMain()
It is possible, however, to manually specify -Wl,-subsystem,windows to the linker and include gdi32 and comdlg32 into the build. This is exactly what -mwindows automates.
Reference.
try --machine-windows option. it helps me when I build asm code:
nasm -f win64 hello.asm
gcc hello.obj --machine-windows -o hello