Eclipse CDT: Is it possible to define a tool in an Eclipse IDE that has no output? - eclipse-cdt

We're using Eclipse as an IDE for our own development tools, and I'm trying to add support for an new tool that will process an executable file, but leave it with the same name (i.e. the tool won't have any obvious outputs). So, for example, if my tool is called "MY_TOOL", then I'm trying to generate a makefile like this:
all: a.exe
a.exe: $(SRC_OBJS)
gcc <BLAH BLAH>
#echo 'Finished building: $#'
MY_TARGET: a.exe
MY_TOOL a.exe
But I'm stuck. I tried omitting "outputType" from the tool definition, but that means I don't define a target in the makefile; if I do include a (fake) outputType, then the (fake) output file ends up on the command line.
So, is there a way to define a tool with no output and still have a valid makefile?

Related

MinGW g++/gcc not compiling with proper path and version command working

i changed the path to the correct directory and when I typed "g++ --version" and "gcc --version" I get the version info. I saved simple.cpp into a folder I made in the directory from path and typed "g++ simple.cpp" into the console and it returned with
C:\Users\guede>g++ simple.cpp
g++: error: simple.cpp: No such file or directory
g++: fatal error: no input files
compilation terminated.
This is the code i am trying to compile as a g++ test
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
return 0;
}
g++ simple.cpp
will look for simple.cpp in the current directory. Since You are executing g++ from C:\MinGW\bin, the compiler will only look in C:\MinGW\bin. It will not look in subdirectories. Since simple.cpp is in C:\MinGW\bin\Cpp_prog, the compiler is not looking for the file in the right place. You could
g++ Cpp_prog\simple.cpp
to specify which directory the file is in, but you do not want the compiler output cluttering up GCC's bin directory. Instead, make yourself a "Workspace" directory somewhere else on the computer, could be in your Documents folder or anywhere else convenient. Inside this workspace make a separate directory for each project so you can keep things organized more easily. Execute the compiler from within the appropriate project directory.
Then either invoke the compiler with
C:\MinGW\bin\g++ simple.cpp
or add C:\MinGW\bin to the user path or system path. See Adding directory to PATH Environment Variable in Windows for help on that.
Later you may find yourself with many different compilers and sometimes several versions of GCC. You don't want to have many locations for g++ in the path because it's easy to call the wrong one. When you get to this point you will likely have had to learn about using build automation tools to assist you with complicated projects. Typically you'll specify the compiler location to the automation tool.
Side note:
dir is the DOS /Windows directory listing command. In the command prompt, type dir it will list all of the files in the current directory. If you're going to take up programming, you'll find it very helpful to learn about the various commandline tools provided by your operating system and development environment.

Compile a single file under CMake project?

I'm developing a C++ project which is going to be enclosed on a bigger one.
I've seen that on the bigger project (is a Qt application and it's being generated from qmake) I am able to compile a single file from the linux command line, just entering the relative path to the specific file as an argument to make.
On the other hand, I'm using CMake for my own project. When I modify some code for a compilation unit and I have to modify its header file, I have to wait a long time to compile its dependencies and then its own source file. But there are some situations in which I would prefer to check whether the source code in the *.cc file is compilable without errors.
Is there a way to generate a Makefile from CMake the way qmake does this? Switching to qmake is not an option anymore.
You do not have to add extra custom targets to your CMake scripts, as the Makefiles generated by CMake already contain .o targets for each .cc file. E.g. if you have a source file called mySourceFile.cc, there will be a Makefile in your build directory that defines a target called <Some Path>/mySourceFile.cc.o. If you cd into your build directory, you can use grep or ack-grep to locate the Makefile that defines this target, then cd into that Makefile's directory and build it.
E.g. suppose the command ack-grep mySourceFile.cc.o prints something like:
foo/bar/Makefile
119:x/y/z/mySourceFile.o: x/y/z/mySourceFile.cc.o
123:x/y/z/mySourceFile.cc.o:
124: # recipe for building target
Then you can build mySourceFile.cc.o by doing:
cd foo/bar && make x/y/z/mySourceFile.cc.o
CMake doesn't have a generic built-in way of doing this (it's an open issue), but if you're using the Ninja generator, you can can use a special Ninja syntax for building just the direct outputs of a given source file. For example, to compile just foo.o you would use:
ninja /path/to/foo.cpp^
Not out-of-the box. CMake does not expose those "internal" makefile rules in the main makefile.
You can do this only if you consider what kind of file structure CMake uses internally. You can e.g. for compiling a single .obj files using CMake generated makefiles call
make -f CMakeFiles/myProg.dir/build.make CMakeFiles/myProg.dir/main.cc.obj
when you have something like
cmake_minimum_required(VERSION 3.1)
project(myProg CXX)
file(WRITE "main.cc" "int main()\n{\nreturn 0;\n}")
add_executable(myProg main.cc)
To build src/foo.cpp alone:
cmake --build . --target src/foo.cpp.o
No, CMake does not offer built-in support to compile single files.
You have to add a target for each object file, maybe by a function iterating over all files of a directory.
Others have suggested ways to find the target name (ending in .cpp.o) from the .cpp filename, but if you already know the name of a target that will trigger compilation of the .cpp file and you're using ninja this suggestion should be easier.
First build the target:
ninja TriggersCppCompilationLib
Assuming your file was changed or was not yet built, ninja will print the full target name. When you see the name come up, hit enter so it is not overwritten. Then simply copy the name from the terminal (e.g. using tmux copy mode).

Why doesn't GDB recognize my library's symbols?

I have a project hierarchy similar to the following:
src/
code.c
ext/
lib/
lib.c
lib.a
bin/
bin-code (+x)
obj/
code.o
lib.c compiles into lib.a using the -g2 flag and then ar.
code.c compiles into bin/obj/code.o using the -g2 flag.
lib.a and code.o are then linked into binary bin-code.
I'm facing a bug within bin-code and I'm trying to use GDB to load the symbols/source for lib so I can examine it with TUI.
I'm adding a breakpoint for a function inside lib.c, which it seems to find as it echos out an address and says it successfully set the breakpoint.
When I run the program and hit the breakpoint, I open TUI with CtrlX / CtrlA, but it claims no source could be found.
Two things worth mentioning:
I have used set substitute-path due to the fact my build system (Tup) uses a FUSE filesystem to enforce read/write operations.
I have tried adding directory entries to the search paths, to no avail.
Am I missing something here? Is there a command I can issue GDB in order for it to rescan directories or something? I can't get the library's source to show up, even though it appears symbols have been loaded.
Most likely gdb fails to find sources of you static library and can't show it's source code.
This may happen if binary was moved to another machine after it was built or sources were moved to another directory. In this case you should properly set substitute-path. You can see where gdb tries to find sources of static library (lib.c) using info sources command. Compare this path with the one where lib.c is actually located and this should help to set proper path substitution.

Error when running make for my Makefile.cpp

I'm getting the error "No targets specified and no makefile found. Stop."
however I'm running the "make" command for my Makefile.cpp in the same directory.
So I just wanted to do a simple makefile to run my three separate files:
all:
g++ gameoflife.cpp functions.cpp header.hpp -o gameoflife
The second line is tabbed once.
Let me know if I need to rename the files or how exactly to run the make file correctly. Thanks. Also this is all being run in a UNIX server with make installed, etc.
The make command uses the makefile with the the name that you specify with the -f option. If you don't use the -f options it uses the file Makefile without the .cpp appendix.
Your editor might have save your Makefile as Makefile.cpp. Check that you use the correct name.
Edit:
To be more specific: The GNU make searches for one of these files in that order:
GNUmakefile
makefile
Makefile

makefile no such file or directory: libxml/xmlstring.h

I'm not used to making makefiles. My old project had all the makefiles in place and I'm making this from scratch for a small test with a lot of canned lib dependencies that I'm not used to either. It's been a few years since I looked at makefiles.
I have a directory called libopcTest with the following in it:
LibOPCTest.cc
LibOPCTest.h
makefile
makefile has this in it:
INC=-I/usr/include/libxml2/libxml
LIB=-L/usr/include/libxml2/libxml
all: LibOPCTest.exe
LibOPCTest.exe: LibOPCTest.o
>tab> gcc -o LibOPCTest.exe LibOPCTest.o
LibOPCTest.o: LibOPCTest.cpp
>tab> gcc -c $(INC) $(LIB) LibOPCTest.cpp
clean:
>tab> rm LibOPCTest.o LibOPCTest.exe
I looked in /usr/include/libxml2/libxml and it does have xmlstring.h in it. I don't see the libxml reference in opc.h, but apparently that's where it comes in, presumably in an include file, like config.h.
Plus, we have LibOPCTest.cpp which #includes <opc/opc.h> and it's own .h file.
main is in LibOPCTest.cpp.
When I type make at the Linux command prompt, I get the following error:
In file included from /usr/include/opc/opc.h:36:0, from LibOPCTest.cpp:1:
/usr/include/opc/config.h:37:30: fatal error: libxml/xmlstring.h: no such file or directory.
Shouldn't I have the libxml with the LIB and INC definition in the makefile pointing to libxml? I don't think I'm supposed to add anything to opc.h, including build it, since it's a canned library.
I was looking at this makefile example, and I think I have everything I need (probably not since it's not building).
I know it's a basic question, but hopefully someone has a good suggestion. Thanks for being nice in advance!!
We decided to put the Linux version of libOPC on hold because there isn't a good 64 bit version and it needs a lot of work.