Eclipse CDT C++ error - c++

I use window Eclipse CDT gdb to debug a C++ program. When I wrote may own makefile as follows
all: prog1
prog1: prog1.cpp
g++ -o prog1 prog1.cpp
It compiled and run successfully. But if I click the debug button, it says no available source main.....
Edit
If I copy the same program to a new C++ project in Eclipse with its internal makefile (instead of writing my own makefile), I can use debug mode. But eventually, I have the following errors.
No source available for "__mingw_CRTStartup How should I do?
Thanks.

Try to change your line
g++ -o porg1 prog1.cpp
to
g++ -o prog1 prog1.cpp
Probably the name of the output (i.e., the program) is wrong, and therefore Eclipse can't launch it.

Related

Compile from linux for windows in eclipse

I'm trying to compile my project in eclipse(linux) for windows.
I followed a guide, then I'm able to compile for windows from command line. I tried to create my project using GCC-toolchain and selecting my prefix/directory
Output on the eclipse console is:
Building file: ../src/provagcc2.cpp
Invoking: Cross G++ Compiler
x86_64-w64-mingw32-g++ -O3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/provagcc2.d" -MT"src/provagcc2.o" -o "src/provagcc2.o" "../src/provagcc2.cpp"
Finished building: ../src/provagcc2.cpp
Building target: provagcc2
Invoking: Cross G++ Linker
x86_64-w64-mingw32-g++ -o "provagcc2" ./src/provagcc2.o
Finished building target: provagcc2
however, it generates a .o file instead of a .exe
-o "provagcc2" looks like you did not specify an extension for the output. There should also be a provagcc2 without extension lying around somewhere as a result. The provagcc2.o file you have found is likely the is the result of compiling. provagcc2.cpp
-o "provagcc2.exe" is what you want on the command line.
To tell Eclipse to name the file correctly, you need to navigate to Project->Properties on the menu. In the Properties dialog that pops up, expand C/C++ Build and select Settings. Select the Build Artifact tab and type exe into the Artifact extension field. Apply and Close and rebuild the project.

Having trouble configuring VS code for c++ programs

I am having some troubles compiling c++ programs in VS code. I followed this answer: How do I set up Visual Studio Code to compile C++ code?
and my Makefile is
CC=g++
CFLAGS=-Wall
.SUFFIXES = .cpp
objs:=$(wildcard *.cpp)
targets:=$(objs:.cpp= )
.PHONY:all
all: $(targets)
.cpp:
$(CC) $(CFLAGS) -std=c++11 -o $# $<
I just want to compile this file which is opened in current window, say 1.cpp and this file does not have any external dependencies
When i try to compile my file (by pressing f8 as given in the answer i linked) i get the following error:
'make' is not recognized as an internal or external command,
operable program or batch file.
I am a beginner, and don't know much about Makefile , any help will be appreciated.
Thanks!
Edit:
I am using Windows subsystem for linux to compile my programs not mingw or cygwin.
Edit:
Now i can use make but i think something is wrong with my Makefile.
I have figured out a simple way:
args doesn't work some reason at least on my system.
So, change command (line 3 of tasks.json)
"command": "g++ -Wall -std=c++14 ${relativeFile};./a.out < input.txt
And now just one button and compile and run!

Running a SFML C++ program with minGW on Windows 10

So I'm trying to run an example SFML program on my Windows laptop. If relevant, the source code is on this page.
So first I make the .o file using this command -
g++ -c a.cpp -ISFML/SFML/include
Where a.cpp is the main file, and my SFML package is located in SFML/SFML.
Then I compile using this command -
g++ a.o -o a -LSFML/SFML/lib -lsfml-graphics -lsfml-window -lsfml-system
When I first ran the program I got the errors about not being able to find certain dlls, sfml-graphics-2 etc. So I found them and put them next to the exe. But now when I run, I get this weird error:
The procedure entry point
_ZNSt7__cxx1112basic_stringSt11char_traitsIcESalcEE7reserveEj could not be located in the dynamic link library.
What is going on here?
As the SFML download page states, You could be using the wrong version of the compiler, other library versions of SFML that you have not removed from your working directory that could mismatch between code and linker. Worst case, if your compiler is not listed there, you have to compile SFML yourself:
Get CMake. Get the source code for 2.4.2 by going to the bottom of the SFML download page. Follow this guide on SFML's GitHub repo. Alternatively, you could use the guide on SFML's page but it is for an older version. It might answer some questions that the first guide misses.
Ones CMake have generated the makefiles, you're on your way to build SFML.
Good luck!
I've had this problem for so long so I just wanted to help someone out who had the same problem. I have a windows 10 FYI and MinGW-w64 8.1.0 (if it doesnt work try a 32 bit mingw instead)
for a debug mode (debug is when your still working on the game and would like command prompt to open whenever you run it)
(make sure your in the right directory first by doing "cd")
g++ -c (file_name).cpp -o (file_name).o -I(path_to)SFML-64-bit/include -g -m64 -Wall &&
g++ (file_name).o -o (game_name).exe -L(path_to)SFML-64-bit/lib -lsfml-graphics -lsfml-window -lsfml-system
The code above when placed in command will compile everything for you if its all in the same directory so make sure you keep an eye out for that
and now for release mode (if you dont want command prompt to show up)
g++ -c (file_name).cpp -o (file_name).o -I(path_to)SFML-64-bit/include -O3 -m64 &&
g++ (file_name).o -o (game_name).exe -L(path_to)SFML-64-bit/lib -lsfml-graphics lsfml-window -lsfml-system -mwindows
Noticed all I added was the -mwindows and the -O3 aswell as removing -g and -Wall which are not necessary since we wont be using command prompt
Make sure to go to SFML/bin and take all the .dlls and put it into the same directory has your .exe sorry xd
Hope this helped.

Command line arguments with CodeBlocks

So, I have been using CodeBlocks IDE for compiling my C and C++ programs. But I want to run the program from the command line. How do I go about this?
P.S I want to run it on Windows platform.
If you want to build a Code::Blocks workspace from the command line, use codeblocks.exe --build --target=W32_Release --no-batch-window-close MyApp.workspace where MyApp.workspace is your workspace. If you want to build a program from the command line without using Code::Blocks, use gcc -O2 program.c -o program where program.c is your program, or g++ -O2 program.cpp -o program for C++. You can get gcc & g++ from here.

gdb not debugging mingw32-g++ compiled code well, but works with g++

I have a simple c++ program I'd like to debug with gdb. When I compile it with
g++ -g main.cpp -o main.exe
I can use gdb just fine with the resulting executable. But when I use
mingw32-g++ -g main.cpp -o main.exe
gdb says things such as
in ?? ()
and functionality is limited; I seem to be able to set break points and run the program, but stepping and such yields the message
Cannot find bounds of current function
As I said, this only happens when compiling with the mingw32-g++ executable, and not with the plain g++ one.
Why is this, and how can I debug executables created with migw32-g++? Both executables run without issue.
Extra info:
Am on Windows 7.
g++ version: 4.8.2
mingw32-g++ version: 4.8.1
gdb version: 7.6.50.[lots of numbers]-cvs
If there's any other info I can provide to help find the issue, just let me know.