I want to be able to use VS2013 as an IDE, for editing my PIC-microchip.
I have MPLAB X IDE 2.20 and the oppropriate compiler installed, and it works OK, but the SVN/GIT client and autocomplete is not so useful as the one i am accustomed to.
Someone has asked this question before, and the answer said that it is possible, but not how.
When compiling in MPLAB, the following is written in output:
make -f nbproject/Makefile-PIC32MX795F512L.mk SUBPROJECTS= .build-conf
make -f nbproject/Makefile-PIC32MX795F512L.mk dist/PIC32MX795F512L/production/project.X.production.hex
"C:\Program Files (x86)\Microchip\xc32\v1.33\bin\xc32-g++.exe" -g -x c++ -c -mprocessor=32MX150F128D -frtti -fexceptions -fno-check-new -fenforce-eh-specs -MMD -MF build/PIC32MX795F512L/production/main.o.d -o build/PIC32MX795F512L/production/main.o main.cpp
"C:\Program Files (x86)\Microchip\xc32\v1.33\bin\xc32-g++.exe" -g -x c++ -c -mprocessor=32MX150F128D -frtti -fexceptions -fno-check-new -fenforce-eh-specs -MMD -MF build/PIC32MX795F512L/production/configuration_bits.o.d -o build/PIC32MX795F512L/production/configuration_bits.o configuration_bits.cpp
"C:\Program Files (x86)\Microchip\xc32\v1.33\bin\xc32-g++.exe" -g -x c++ -c -mprocessor=32MX150F128D -frtti -fexceptions -fno-check-new -fenforce-eh-specs -MMD -MF build/PIC32MX795F512L/production/interrupts.o.d -o build/PIC32MX795F512L/production/interrupts.o interrupts.cpp
"C:\Program Files (x86)\Microchip\xc32\v1.33\bin\xc32-g++.exe" -g -x c++ -c -mprocessor=32MX150F128D -frtti -fexceptions -fno-check-new -fenforce-eh-specs -MMD -MF build/PIC32MX795F512L/production/system.o.d -o build/PIC32MX795F512L/production/system.o system.cpp
"C:\Program Files (x86)\Microchip\xc32\v1.33\bin\xc32-g++.exe" -g -x c++ -c -mprocessor=32MX150F128D -frtti -fexceptions -fno-check-new -fenforce-eh-specs -MMD -MF build/PIC32MX795F512L/production/user.o.d -o build/PIC32MX795F512L/production/user.o user.cpp
"C:\Program Files (x86)\Microchip\xc32\v1.33\bin\xc32-g++.exe" -mprocessor=32MX150F128D -o dist/PIC32MX795F512L/production/DDG.X.production.elf build/PIC32MX795F512L/production/main.o build/PIC32MX795F512L/production/configuration_bits.o build/PIC32MX795F512L/production/exceptions.o build/PIC32MX795F512L/production/interrupts.o build/PIC32MX795F512L/production/system.o build/PIC32MX795F512L/production/user.o -Wl,--defsym=__MPLAB_BUILD=1,--defsym=_min_heap_size=4096,--defsym=_min_stack_size=4096
"C:\Program Files (x86)\Microchip\xc32\v1.33\bin"\\xc32-bin2hex dist/PIC32MX795F512L/production/DDG.X.production.elf
Although this is for AVR, this might help you with configuring VS2013 for PIC: http://www.instructables.com/id/Use-Visual-Studio-2010-to-Compile-AVR-Hex-Files/
Related
I am trying to convert a (sloppy) Makefile into a CMakeLists.txt to better work with my IDE (CLion).
My Makefile is as follows:
all:
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -Os -g -m32 -I. -c -o bin/boot0.o boot/boot0/boot0.S
ld -nostdlib -m elf_i386 -N -e start -Ttext 0x7c00 -o bin/boot0.elf bin/boot0.o
objcopy -S -O binary bin/boot0.elf bin/boot0
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -Os -g -m32 -I. -c -o bin/boot1.o boot/boot1/boot1.S
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -Os -g -m32 -I. -c -o bin/boot1main.o boot/boot1/boot1main.c
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -Os -g -m32 -I. -c -o bin/boot1lib.o boot/boot1/boot1lib.c
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -Os -g -m32 -I. -c -o bin/exec_kernel.o boot/boot1/exec_kernel.S
ld -nostdlib -m elf_i386 -N -e start -Ttext 0xd7000 -o bin/boot1.elf bin/boot1.o bin/boot1main.o bin/boot1lib.o bin/exec_kernel.o
objcopy -S -O binary bin/boot1.elf bin/boot1
gcc -MD -fno-builtin -nostdinc -fno-stack-protector -D_KERN_ -Ikern -Ikern/kern -I. -m32 -O0 -c -o bin/entry.o kern/init/entry.S
ld -o kernel -nostdlib -e start -m elf_i386 -Ttext=0x00100000 bin/entry.o -b binary
dd if=/dev/zero of=project0.img bs=512 count=256
parted -s project0.img "mktable msdos mkpart primary 63s -1s set 1 boot on"
dd if=bin/boot0 of=project0.img bs=446 count=1 conv=notrunc
dd if=bin/boo1 of=project0.img bs=512 count=62 seek=1 conv=notrunc
dd if=kern/init/kernel of=project0.img bs=512 seek=63 conv=notrunc
Mostly I am using make just to run the commands.
I am running into trouble with the fact that I have three different sets of linker flags (one each for boot0, boot1, and kern.)
Should I create separate CMakeLists.txt in each subdirectory (boot0, boot1, and kern) and then have a main one that runs each in turn and then handles the dd and parted usage, is there a better way to do this, or is CMake not an appropriate tool here?
Please have short-cuts for the compiler commands first. Then write the rule to create the first target on which the second target is dependent. Then since the first target is created; now use it to create the second target.
The below makefile does not have target for making OBJECTS but still the make is forming the rule and makes the OBJECTS and makes the final all.exe. I am not sure how does it work. Does make have mechanism to create rules if they are not available in the makefile for the dependencies?
SOURCE=$(wildcard Source/\*.cpp)
TEST=$(wildcard Source/Tests/\*.cpp)
OBJECTS=$(SOURCE:.cpp=.o) $(TEST:.cpp=.o)
CXXFLAGS= -O3 -fstack-usage -MMD
all:$(OBJECTS)
g++ $(CXXFLAGS) -o $# $(OBJECTS)
print::
#echo $(SOURCE)
#echo $(OBJECTS)
#echo $(TEST)
clean:
rm -rf Source/*.o Source/Tests/*.o *.exe
Console Output:
$ make
g++ -O3 -fstack-usage -MMD -c -o Source/main.o Source/main.cpp
g++ -O3 -fstack-usage -MMD -c -o Source/Tests/TestList.o Source/Tests/TestList.cpp
g++ -O3 -fstack-usage -MMD -c -o Source/Tests/TestLinkedlist.o Source/Tests/TestLinkedlist.cpp
g++ -O3 -fstack-usage -MMD -o all Source/main.o Source/Tests/TestList.o Source/Tests/TestLinkedlist.o
Folder Structure:
Yes, GNU make has a full suite of built-in rules.
See the manual: https://www.gnu.org/software/make/manual/html_node/Catalogue-of-Rules.html
I would like to create a generic Makefile that builds several executables using different compiler flags for each executable without using shell commands. The executable file name should be composed from the source file and a unique post fixed name. It should also produce an assembly or preprocessor file per source file if needed.
For the target BIN_BDG_FILES, the "$<" (exercise-1.1.0.c ) is always the first item from the list (exercise-1.1.0.c exercise-1.1.1.c exercise-1.2.0.c exercise-1.2.1.c) as expected. I tried without success to modify the SRC_FILES using the filter-out function. My intent was to remove the first item from the list for each Target, so that the first item corresponds to the correct target. I am not sure this is the correct approach. Your comments are welcome.
i.e.
This is my attempt at using built in make constructs.
$(BIN_DBG_FILES): $(SRC_FILES)
$(CC) $(DBG_CFLAGS) $(IFLAGS) $< -o $#
echo SRC_FILES := $(filter-out $<, $(SRC_FILES))
Makefile
SHELL = bash
SRC_FILES = $(wildcard *.c)
BIN_FILES = $(patsubst %.c,%,$(SRC_FILES))
BIN_DBG_FILES = $(patsubst %.c,%-dbg,$(SRC_FILES))
SRC_PRE = $(patsubst %.c,%-pre,$(SRC_FILES))
CC = gcc
WARNINGS := -Wall
CFLAGS = -O2 -std=c99 $(WARNINGS)
DBG_CFLAGS = -g -O -std=c99 $(WARNINGS)
PRE_FLAG = -E
IFLAGS = -I.
all: $(BIN_FILES) $(BIN_DBG_FILES) MK-BASH
$(BIN_DBG_FILES): $(SRC_FILES)
$(CC) $(DBG_CFLAGS) $(IFLAGS) $< -o $#
MK-BASH::
for src in $(SRC_FILES); do \
echo $(CC) $(DBG_CFLAGS) $(IFLAGS) $$src -o $${src%.c}-dbg; \
$(CC) $(DBG_CFLAGS) $(IFLAGS) $$src -o $${src%.c}-dbg; \
$(CC) $(DBG_CFLAGS) $(IFLAGS) $$src -o $${src%.c}-dbg; \
$(CC) $(PRE_FLAG) $$src > $${src%.c}-pre; \
done
clean:
rm -f $(BIN_FILES) *-dbg *-pre
This is the output from executing make command.
This is the output from the target BIN_FILES.
gcc -O2 -std=c99 -Wall exercise-1.1.0.c -o exercise-1.1.0
gcc -O2 -std=c99 -Wall exercise-1.1.1.c -o exercise-1.1.1
gcc -O2 -std=c99 -Wall exercise-1.2.0.c -o exercise-1.2.0
gcc -O2 -std=c99 -Wall exercise-1.2.1.c -o exercise-1.2.1
This is the output from target BIN_DBG_FILES which uses the first source file on the list to build all targets. It should use the appropriate file (exercise-1.1.1.c) to build each target file (exercise-1.1.1-dbg).
gcc -g -O -std=c99 -Wall -I. **exercise-1.1.0.c** -o exercise-1.1.0-dbg
gcc -g -O -std=c99 -Wall -I. **exercise-1.1.0.c** -o exercise-1.1.1-dbg
gcc -g -O -std=c99 -Wall -I. **exercise-1.1.0.c** -o exercise-1.2.0-dbg
gcc -g -O -std=c99 -Wall -I. **exercise-1.1.0.c** -o exercise-1.2.1-dbg
This is the output from the target MK-BASH using shell commands.
for src in exercise-1.1.0.c exercise-1.1.1.c exercise-1.2.0.c exercise-1.2.1.c; do \
echo gcc -g -O -std=c99 -Wall -I. $src -o ${src%.c}-dbg; \
gcc -g -O -std=c99 -Wall -I. $src -o ${src%.c}-dbg; \
gcc -g -O -std=c99 -Wall -I. $src -o ${src%.c}-dbg; \
gcc -E $src > ${src%.c}-pre; \
done
output:
gcc -g -O -std=c99 -Wall -I. exercise-1.1.0.c -o exercise-1.1.0-dbg
gcc -g -O -std=c99 -Wall -I. exercise-1.1.1.c -o exercise-1.1.1-dbg
gcc -g -O -std=c99 -Wall -I. exercise-1.2.0.c -o exercise-1.2.0-dbg
gcc -g -O -std=c99 -Wall -I. exercise-1.2.1.c -o exercise-1.2.1-dbg
Use a pattern rule:
DBG: $(BIN_DBG_FILES)
%-dbg: %.c
#echo $(CC) $(DBG_CFLAGS) $(IFLAGS) $< -o $#
I am relatively new to hand crafted make files. I have put together a basic make file for building a library. I want to keep all the temporary .o files in a build directory and have the built executable stored in a bin directory.
My directory structure looks like this:
root
src/
include/
build/
bin/
Makefile
and this is what my make file looks like:
SHLIB = pg_extlib
SRC = src/file1.c \
src/file2.c
OBJS = build/file1.o \
build/file2.o
debug_build:
gcc -g -fPIC -c $(SRC) -I`pg_config --includedir` -I`pg_config --includedir-server` -I/some/required/path/include -Iinclude
gcc -shared -o bin/$(SHLIB).so $(OBJS) -lm -lpq -lmylib_core
clean:
rm -f $(SHLIB) $(OBJS)
The .o files are placed correctly in the build folder, but they also appear in the root folder (where the Makefile resides). How do I fix this?
I see how you're getting object (.o) files in the root folder, but I have no idea how you're getting them in the build folder.
Let's take this in stages. First we'll give the object files their own rules:
# Note the use of "-o ..."
build/file1.o:
gcc -g -fPIC -c src/file1.c -I`pg_config --includedir` -I`pg_config --includedir-server` -I/some/required/path/include -Iinclude -o build/file1.o
build/file2.o:
gcc -g -fPIC -c src/file2.c -I`pg_config --includedir` -I`pg_config --includedir-server` -I/some/required/path/include -Iinclude -o build/file2.o
debug_build: $(OBJS)
gcc -shared -o bin/$(SHLIB).so $(OBJS) -lm -lpq -lmylib_core
This is effective, but crude. The object files now go into build/, but there's lots of redundancy, no dependency handling. So we put in prerequisites, and assuming you're using GNUMake (which you should), we can use Automatic Variables (and I'll abbreviate the -I string just for readability):
build/file1.o: src/file1.c
gcc -g -fPIC -c $< -I... -o $#
build/file2.o: src/file2.c
gcc -g -fPIC -c $< -I... -o $#
debug_build: $(OBJS)
gcc -shared -o bin/$(SHLIB).so $^ -lm -lpq -lmylib_core
Notice that the commands in the object rules are now exactly the same. So we can combine those two rules a couple of different ways. The simplest is:
build/file1.o: src/file1.c
build/file2.o: src/file2.c
build/file1.o build/file2.o:
gcc -g -fPIC -c $< -I... -o $#
Now one or two more little tweaks and we're good to go:
build/file1.o: src/file1.c
build/file2.o: src/file2.c
build/file1.o build/file2.o:
gcc -g -fPIC -c $< -I`pg_config --includedir` -I`pg_config --includedir-server` -I/some/required/path/include -Iinclude -o $#
debug_build: $(OBJS)
gcc -shared -o bin/$(SHLIB).so $^ -lm -lpq -lmylib_core
There are more sophisticated tricks, but that should be plenty for now.
I am trying to compile a project to run on an ARM board that I have. To use the debugger, I have to put debugging symbols in the resulting .elf file.
I configured everything and ran my makefile, which produced the following results:
arm-elf-gcc -x assembler-with-cpp -c -mcpu=arm7tdmi-s -g -gdwarf-2 -Wa,-amhls=src/crt.lst src/crt.S -o src/crt.o
arm-elf-gcc -c -mcpu=arm7tdmi-s -O0 -g -gdwarf-2 -mthumb-interwork -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=src/main.lst -MD -MP -MF .dep/main.o.d -I . -I./inc src/main.c -o src/main.o
arm-elf-gcc -c -mcpu=arm7tdmi-s -O0 -g -gdwarf-2 -mthumb-interwork -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=library/md5.lst -MD -MP -MF .dep/md5.o.d -I . -I./inc library/md5.c -o library/md5.o
arm-elf-gcc -c -mcpu=arm7tdmi-s -O0 -g -gdwarf-2 -mthumb-interwork -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=library/bignum.lst -MD -MP -MF .dep/bignum.o.d -I . -I./inc library/bignum.c -o library/bignum.o
arm-elf-gcc ./src/crt.o ./src/main.o ./library/md5.o ./library/bignum.o -mcpu=arm7tdmi-s -g -nostartfiles -T./prj/LPC2138_flash.ld -Wl,-Map=testFLASH.map,--cref,--no-warn-mismatch -nostdlib -L. -Wl,-static -ffunction-sections -Wl,--gc-sections -Wl,-s -fdata-sections -lc -lg -lnosys -o testFLASH.elf
I have put in the -g flags, but when I try to find debugging symbols, I get only :
C:\Users\stkerr\Code\EclipseWorkspace\LibraryWork>objdump -g testFLASH.elf
testFLASH.elf: file format elf32-little
This is further confirmed when I try to open the .elf file in my debugger, I get an error about the file not having debugging symbols.
Can anyone point to an error in my arm-elf-gcc calls or a flag that I am missing?
After poking around a little more in the documentation, the -Wl,-s is the problem.
It strips all symbols from the resulting executable, including the debugging information.