Custom runner for whole c++ projects with library and header paths


#1

Hi all,

is it there a custom runner already implemented that compiles all the cpp files in the workspace and link them with third party shared libraries .so placed in a directory. In both debuging and release mode. Thanks


C++ build and debug: basic questions
Use debugger panel on the right while launching application from consile
#2

Hi,

There’s isn’t a custom runner like that at the moment, but you can create a makefile for your project that builds all the relevant code according to your needs. Once the makefile is created, you can then run that makefile using the ‘Shell Command’ runner.

I hope this helps.

Regards,
​Mutahhir


#3

I already have it already. But I thought that I need to create a custom runner to be able to use the debugger on the right. How could I use the debugger UI (watch expressions, call stack, local variables, breakpoints…) when using makefiles from the console? Thanks


#4

Hi,

Ok, I wanted to see how that could be done :slight_smile: so I did some testing. It was a very basic experiment, but it should be able to scale, no problem.

I took the C++ (Simple) runner and modified it to run a makefile to build things:


// This file overrides the built-in C++ (simple) runner
// For more information see http://docs.c9.io:8080/#!/api/run-method-run
{
  "script": [
    "set -e",
    "cd /home/ubuntu/workspace",
    "if [ \"$debug\" == true ]; then ",
    "make debug",
    "chmod 755 \"app.o\"",
    "gdbserver --once :15470 \"app.o\" $args",
    "else",
    "make res",
    "chmod 755 app.o",
    "app.o $args",
    "fi"
  ],
  "info": "Running Project",
  "debugport": 15470,
  "debugger": "gdb",
  "executable": "app.o",
  "maxdepth": 50,
  "$debugDefaultState": false,
  "env": {},
  "selector": "^.*\\.(cpp|cc)$"
}

There are two things to note in the above. First is that rather than compiling a single C++ file, I’m running the make command, which builds the project. Second, I assume the Makefile is in the workspace directory. Now, replace the make command with whatever your debug makefile looks like. I just used the default Makefile command that was used in the original runner:

debug: hello-cpp-world.cc
	/usr/bin/g++ -ggdb3 -std=c++11 $< -o app.o

res: hello-cpp-world.cc
	/usr/bin/g++ -std=c++11 $< -o app.o

With the above two pieces, clicking run should compile your project and start debugging it without issues.

I hope this helps.

Regards,
​Mutahhir


Use debugger panel on the right while launching application from consile
#5

Hi Mutahhir, thank you very much for your reply. I’m having still problems after updating the runner.

This is what I have, where exactly do I have to include this last to pieces you wrote?

External libraries are located at /home/ubuntu/workspace/libs

External headers are located at /home/ubuntu/workspace/include

My project’s cpp’s and h’s are at /home/ubuntu/workspace

My makefile is located at /home/ubuntu/workspace/makefiles
i usually call the command:

make -f /home/ubuntu/workspace/makefiles/makefile all

Finally my makefile looks like the following

-include ../makefile.init

RM := rm -rf

# All of the sources participating in the build are defined here
-include sources.mk
-include src/subdir.mk
-include subdir.mk
-include objects.mk

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C++_DEPS)),)
-include $(C++_DEPS)
endif
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
ifneq ($(strip $(CC_DEPS)),)
-include $(CC_DEPS)
endif
ifneq ($(strip $(CPP_DEPS)),)
-include $(CPP_DEPS)
endif
ifneq ($(strip $(CXX_DEPS)),)
-include $(CXX_DEPS)
endif
ifneq ($(strip $(C_UPPER_DEPS)),)
-include $(C_UPPER_DEPS)
endif
endif

-include ../makefile.defs

# Add inputs and outputs from these tool invocations to the build variables 

# All Target
all: PDMain

# Tool invocations
PDMain: $(OBJS) $(USER_OBJS)
	@echo 'Building target: $@'
	@echo 'Invoking: GCC C++ Linker'
	g++ -o PDMain -L../lib -I../include -Wl,-rpath=../lib $(OBJS) $(USER_OBJS) $(LIBS)
	@echo 'Finished building target: $@'
	@echo ' '

# Other Targets
clean:
	-$(RM) $(OBJS)$(C++_DEPS)$(C_DEPS)$(CC_DEPS)$(LIBRARIES)$(CPP_DEPS)$(CXX_DEPS)$(C_UPPER_DEPS) PDMain
	-@echo ' '

.PHONY: all clean dependents
.SECONDARY:

-include ../makefile.targets

#6

After a few more modifications I was able to make the runner compile and run, but still cannot use the debugger on the right.

I added this snippet to my makefile:

debug: $(OBJS) $(USER_OBJS)
	@echo 'Building target debug: $@'
	@echo 'Invoking: GCC C++ Linker'
	g++ -ggdb3 -o PDMain -L../lib -I../include -Wl,-rpath=../lib $(OBJS) $(USER_OBJS) $(LIBS)
	@echo 'Finished building target: $@'
	@echo ' '

But there is also included in the makefile the file subdir.mk that supply rules for building sources with the following:

# Add inputs and outputs from these tool invocations to the build variables 
CPP_SRCS += \
../PDMain.cpp \

OBJS += \
./src/PDMain.o \

CPP_DEPS += \
./src/PDMain.d \

# Each subdirectory must supply rules for building sources it contributes
src/%.o: ../%.cpp
	@echo 'Building file: $<'
	@echo 'Invoking: GCC C++ Compiler'
	g++ -std=c++11 -fPIC -L../lib -I../include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<" -Wl,-rpath=../lib
	@echo 'Finished building: $<'
	@echo ' '

I think the problem must be related with this last one. I tried added -ggdb3 there but debugger still not working.
Any help would greatlly appreciated


#7

any success with a start the debugging here in C9?