Trouble compiling in the right "format" with Makefile?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
As you see i want to compile with the arm-angstrom...-g++ compiler, but when i do compile the objects files made is for Intel80386 ????.. And therefore the executable never gets made?.
Someone know why the generated object files becomes Inten80386 objectfiles instead of arm?
Although you posted this as a question about Makefiles, I question whether you actually have a properly installed ARM Angstrom cross toolchain. Can you run the specified compiler outside of a Makefile, and still create ARM binaries? How are you determining that the binaries are x86 format?
I have compiled before without using Makefile, and then it compiles just fine. Actually I have also compiled a "Hello_world.cpp" with a Makefile similar to the one shown, just with Hello_world.cpp as the only document in the variable SOURCES.
I determine the file format by typing:
>$ file main.o
In my project folder I actually have 2 makefiles: Makefile.host and Makefile.target where Makefile.host works perfectly fine, but Makefile.host wont
Okay, when the make runs, do you see the correct version of gcc being used? Have you removed the old object code (make clean) and re-tried? Is the correct compiler in $PATH (you don't have a fully qualified filespec for $CC).
--- rod.
BTW: you must have mistyped when you wrote: 'Makefile.host works perfectly fine, but Makefile.host wont'
Caveat: I don't do any cross-compiling. Forgive me if I misunderstand the process, but...
The output you show indicates that make is relying on implicit rules to create the object files. The implicit rule invokes plain-jane "g++" -- not "arm-angstrom-linux-gnueabi-g++" -- to create the object files.
I assume you need "arm-angstrom-linux-gnueabi-g++" to create those files.
To do so, you need to modify your Makefile and add something like this:
Code:
%.o : %.cpp
${CC} -c $<
It appears that your "parts" target may have been what you thought would perform this step.
As an alternative to the above, depending on what your ultimate goal is, you could probably just replace your "parts" target definition with:
Code:
#parts: ${SOURCES}
${OBJECTS} : ${SOURCES}
-or-
Code:
${OBJECTS} : parts
parts: ${SOURCES}
The original approach using "%.o : %.cpp" is the more typical/standard way of doing it in my experience.
EDIT:
Also, assuming you're using GNU make, you probably need to add:
Code:
.PHONY : clean
Which will make sure that the clean target always executes its target instructions when invoked.
Last edited by Dark_Helmet; 02-22-2012 at 03:22 PM.
I think the OP should consider defining CXX in lieu of using CC, which is for C programs. CXX is interpreted by 'make', along with CXXFLAGS if compiler flags are needed, for building C++ files. This would obviate the need to define a rule to make the object files, since 'make' already has a built-in rule for this.
Last edited by dwhitney67; 02-23-2012 at 04:48 AM.
It works!!.. I deleted the parts target and inserted
Code:
%.o : %.cpp
${CC} -c $<
So thanks! .. But what does the 2 lines exactly?
And where should I insert the ".PHONY : clean" line, so the clean target is called every time I run the makefile?
Oh and one more question: How can I save my object files in an other directory?.. for example if my makefile is in home/user/project1 and I want to save my object files in home/user/project1/target?
It works!!.. I deleted the parts target and inserted
Code:
%.o : %.cpp
${CC} -c $<
So thanks! .. But what does the 2 lines exactly?
And where should I insert the ".PHONY : clean" line, so the clean target is called every time I run the makefile?
Oh and one more question: How can I save my object files in an other directory?.. for example if my makefile is in home/user/project1 and I want to save my object files in home/user/project1/target?
The percent character denotes a wildcard. Thus to make foo.o, 'make' looks for foo.cpp. The $< refers to the dependency, which is %.cpp. The -c option instructs the compiler to build only an object (.o) file.
You really should be using CXX, not CC, for building C++ files.
And where should I insert the ".PHONY : clean" line, so the clean target is called every time I run the makefile?
I usually place it right before the clean target itself.
But you may have misunderstood what I meant--my wording was poor. Adding ".PHONY : clean" to the Makefile will force make to execute the instructions for the "clean" target everytime you invoke "make clean." That is, the "phony" designation turns off make's internal decision making for whether the target should or should not be updated.
It will not cause make to execute the clean target commands everytime you run make.
You might be able to accomplish what you're thinking by adding the clean target as a dependency to another target. Though, I think the make documentation says that the order of dependency updates is not guaranteed. So doing so might cause the clean instructions to run after other dependencies have been built. Also, by running clean everytime, you eliminate one of the main reasons for using make to begin with: only re-compiling the parts that have been changed since your last compile.
EDIT:
Collecting your object files in another directory will require more work. I recently came across a post on another forum. The second answer (added by anon and edited by Daryl Spitzer) gives a solution to that particular problem with the use of the patsubst() function provided by make.
Last edited by Dark_Helmet; 02-23-2012 at 01:06 PM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.