Linking Code/Objects Using DevC++ IDE

Pages: 12
You seem to be following the instructions that we provided just fine so don't get frustrated at that. I hate to say it but this seems to be a Dev-C++ bug, I fought with this IDE a lot before giving up so don't worry I'll still help you.

When the Compile button is pushed a file called MAKEFILE, Makefile, Makefile.win or something like that is created by the IDE in the same directory as the cpp and .h files you are working with are, also made are several .o files under a folder called 'Objects'. Do me a favor and list the names of the .o files in your next post and copy paste everything in the Makefile inside a set of code blocks. This is an unusual request but I have a feeling that I know what the problem is and this is the only way I know how to confirm it. If you have trouble opening the Makefile you can use Notepad, Notepad++ or Wordpad, even if it does not have a file extension.
Last edited on
double.h: no such file or directory


It's not finding your header file.

All your files should be in the same directory. Typically the IDE will create a project folder that is named whatever you named your project.

The .h and .cpp files either go in that folder, or they go in a /src/ folder that's in that folder, or something like that. It depends on the IDE.


But really -- I don't know how you could be screwing this up, it's very simple.

Start over from scratch.

1) Open your IDE
2) Make a new project. if there are options as for what type of project to make, choose "Empty C++ project" or whatever sounds closest to that
3) Once the project is created look around for an "Add new item to project" option in the menus
4) Name the new item "main.cpp" and copy the code I gave your for main.cpp into that file.
5) Repeat steps 3,4 for "double.h" and "double.cpp"
6) Build the project


Even an outdated IDE like Dev-C++ should be able to do this without any trouble. You must be doing something crazy.


EDIT: I just saw computergeek's reply. You can go that route if you'd like, but getting into makefiles will likely just confuse you even more, and dealing with them is totally unnecessary (the whole point of using an IDE is so you don't have to deal with them). I've been coding C++ for over a decade and I never once had to even look at a makefile, nevermind write/modify one.
Last edited on
@ Disch: I agree, there is no need for the OP to go into the Makefile, I want to confirm this for myself. Also I have a pretty firm grasp on how they work so I may be able to help the OP edit this if your solution doesn't work.
Here we go sir:

MAKEFILE quoted in a code block:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Project: Project1
# Makefile created by Dev-C++ 4.9.9.2

CPP  = g++.exe
CC   = gcc.exe
WINDRES = windres.exe
RES  = 
OBJ  = Untitled1.o Untitled2.o $(RES)
LINKOBJ  = Untitled1.o Untitled2.o $(RES)
LIBS =  -L"E:/CPP/Dev-Cpp/lib" Untitled2.cpp  
INCS =  -I"E:/CPP/Dev-Cpp/include" 
CXXINCS =  -I"E:/CPP/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"E:/CPP/Dev-Cpp/include/c++/3.4.2/backward"  -I"E:/CPP/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"E:/CPP/Dev-Cpp/include/c++/3.4.2"  -I"E:/CPP/Dev-Cpp/include" 
BIN  = Project1.exe
CXXFLAGS = $(CXXINCS)  
CFLAGS = $(INCS)  
RM = rm -f

.PHONY: all all-before all-after clean clean-custom

all: all-before Project1.exe all-after


clean: clean-custom
	${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
	$(CPP) $(LINKOBJ) -o "Project1.exe" $(LIBS)

Untitled1.o: Untitled1.cpp
	$(CPP) -c Untitled1.cpp -o Untitled1.o $(CXXFLAGS)

Untitled2.o: Untitled2.cpp
	$(CPP) -c Untitled2.cpp -o Untitled2.o $(CXXFLAGS)


Name of .o files:
main
untitled1
untitled2
Now that you guys mention the directories of where the files are, and mention im doing something crazy you may be right....

when I save every source file I save it directly in the devcpp folder.

E:/CPP/Dev-Cpp/untiltled1
E:/CPP/Dev-Cpp/untiltled2
E:/CPP/Dev-Cpp/untiltled3

where untitled 1 2 and 3 represent the cpp, cpp and h files.

must it go in seperate folder, or a location outside devcpp folder?
Is this maybe it? Ill check reply tomorrow, I must sleep now 01:00 am here.
Untitled2 your cpp file should NOT be listed as a lib, your main.o file isn't even mentioned in this file. Also it appears that even though you told us you named your header file as a ".h" you linker is expecting a ".cpp". Either you did something and didn't tell us or your Linker is FUBAR.

The problem doesn't seem to be with anything you are doing, unless you are writing them as cpp files then changing the extention or something equally as silly as that. We can confidently blame the IDE for your issues.

Here:
http://wxdsgn.sourceforge.net/
Trust me, at the level you are at you will not see ANY difference. Also there is no need to modify PATH or anything crazy like that it's really easy to install.

EDIT: Having read your last post and reread you Makefile I can tell you that you are saving the files wrong, and you don't have main.cpp included in your project at all. First of all you should be putting your projects in their own folders if nothing else then to orginize them, second it takes like 2 seconds to type a name so please stop being lazy :p. You should include the extentions to the files when you save them so that your IDE doesn't have to assume anything at all. Do this, relink and recompile everything and let us know how it went. I will be stalking this thread until we hear back from you ;).
Last edited on
when I save every source file I save it directly in the devcpp folder.


This is probably wrong. You should have a separate folder for your project.

But the IDE should be managing it anyway. Like I said, just do the steps I outline above. The IDE will default to the right directory if you create the files from within the IDE.

You shouldn't have to do ANYTHING from outside the IDE. No creating files, no examinig makefiles, no nothing. Just open the IDE and try to do the steps above.

When you start mixing IDE stuff with non-IDE stuff, that's when you start confusing the IDE and you run into problems like this.

where untitled 1 2 and 3 represent the cpp, cpp and h files.


Except they're named wrong. They should be named what I told you to name them. Obviously if you're telling the compiler to look for "double.h" it's not going to find it unless you have a file named "double.h"
HOLY SHIT IT WORKS!!!!!!!!!!!!!! HAHAHAHAA!!! IM SO HAPPY NOW :D

AAAAAAAAAAAHAAAAAAAAAAAA!!

Did exactly as told:

1) Put a seperate folder in dev folder
2) all my source files were saved there and explicitly saved .cpp and .h without compiler assuming too much
3) they were named properly as main double etc etc...

Computer Geek01 and Dirch thanks for guiding me the right path.

If I have any more problems ill PM you guys directly :D :D
Last edited on
Happy to help.

I'm glad to hear it's working! =)

If I have any more problems ill PM you guys directly :D :D


Honestly, I'd prefer it if you post on the forums. That way other people have the benefit of seeing the answer/solution. Plus it's better for you because other people can jump in and correct us if when we're wrong.
I'm glad to hear that it worked. Just remember copy pasting the makefile like that is not something most people will have asked you to do, so stay out of it until you have a firm grasp of C++. You should know what all of the components of you programs do eventually but it's not important right now.

Although I would respond to your PM's I would like to point out that they do not show up in Google cache, so please post questions in the public area so that everyone can benefit from the results. Another reason is that there are far more experianced and better programmers on this site, so I may not always be the right choice.
yeah the PM bit was just a joke, ofcoarse ill ask public :D

Thanks again guys. On a final note, I saw that wxDevcpp IDE you posted and I must say its very impressive... it allows you to build GUI's in a more user friendly manner?! Thats something for me to look at in the near future.
Last edited on
Topic archived. No new replies allowed.
Pages: 12