Skip to content

Instantly share code, notes, and snippets.

@iwatake2222
Last active July 1, 2018 12:18
Show Gist options
  • Save iwatake2222/efdf5d9c2f324fc6a5e146f17da937af to your computer and use it in GitHub Desktop.
Save iwatake2222/efdf5d9c2f324fc6a5e146f17da937af to your computer and use it in GitHub Desktop.
ラズパイ用のC/C++開発環境をお手軽に構築する ref: https://qiita.com/take-iwiw/items/46119bb7d41c6030d34f
{
"host": "192.168.1.88",
"port": 22,
"username": "pi",
"password": "rasp",
"protocol": "sftp",
"agent": null,
"privateKeyPath": null,
"passphrase": null,
"passive": false,
"interactiveAuth": false,
"remotePath": "/home/pi/MyCProject",
"uploadOnSave": true,
"syncMode": "update",
"watcher": {
"files": false,
"autoUpload": false,
"autoDelete": false
},
"ignore": [
"**/.vscode/**",
"**/.git/**",
"**/.DS_Store"
]
}
#include <stdio.h>
void ppp()
{
printf("ppp\n");
}
#include <stdio.h>
#include "aaa.h"
#include "subA.h"
#include "subB.h"
int main()
{
printf("Hello World\n");
ppp();
printf("%d %d\n", subFunc1(), subFunc2());
printf("%d %d\n", subFunc3(), subFunc4());
return 0;
}
include makefile_config
TARGET = a.out
SRCS = main.cpp aaa.cpp
SUBDIRS = subStaticModuleA subDynamicModuleB
INCLUDES += -IsubStaticModuleA -IsubDynamicModuleB
SUBS = subStaticModuleA/subModuleA.a
LIBS += -L./ -lsubModuleB
all: sub_target $(TARGET)
$(TARGET): $(OBJS) $(SUBS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(SUBS) $(LIBS)
.PHONY: sub_target
sub_target:
ifdef SUBDIRS
$(foreach subdir,$(SUBDIRS),cd $(subdir) && $(MAKE) && cd ../ &&) cd ./
endif
.PHONY: clean
clean:
$(DEL) *.o *.a *.exe *.dll *.so *.out
ifdef SUBDIRS
$(foreach subdir,$(SUBDIRS),cd $(subdir) && $(MAKE) clean && cd ../ &&) cd ./
endif
## environment
#PLATFORM = WIN_MINGW
PLATFORM = LINUX
BINARY = DEBUG
#BINARY = RELEASE
ifeq ($(PLATFORM), WIN_MINGW)
# for win
MAKE = mingw32-make
#DEL = del
DEL = rm -f
CC = g++
AR = ar
else
# for linux
MAKE = make
DEL = rm -f
CC = g++
AR = ar
endif
ifeq ($(BINARY), DEBUG)
CFLAGS = -g3 -O0 -Wall
else
CFLAGS = -O3 -Wall
endif
LDFLAGS =
LIBS = -lm
OBJS = $(SRCS:.cpp=.o)
#OBJS = *.o
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $<
.cpp.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $<
include ../makefile_config
TARGET = ../libsubModuleB.so
SRCS = subB1.cpp subB2.cpp
INCLUDES =
SUBS =
SUBDIRS =
all: sub_target $(TARGET)
$(TARGET): $(OBJS) $(SUBS)
$(CC) $(LDFLAGS) -shared -fPIC -o $@ $(OBJS) $(SUBS)
.PHONY: sub_target
sub_target:
ifdef SUBDIRS
$(foreach subdir,$(SUBDIRS),cd $(subdir) && $(MAKE) && cd ../ &&) cd ./
endif
.PHONY: clean
clean:
$(DEL) *.o *.a *.exe *.dll
ifdef SUBDIRS
$(foreach subdir,$(SUBDIRS),cd $(subdir) && $(MAKE) clean && cd ../ &&) cd ./
endif
include ../makefile_config
TARGET = subModuleA.a
SRCS = subA1.cpp subA2.cpp
INCLUDES =
SUBS =
SUBDIRS =
all: sub_target $(TARGET)
$(TARGET): $(OBJS) $(SUBS)
$(AR) r $@ $(OBJS) $(SUBS)
.PHONY: sub_target
sub_target:
ifdef SUBDIRS
$(foreach subdir,$(SUBDIRS),cd $(subdir) && $(MAKE) && cd ../ &&) cd ./
endif
.PHONY: clean
clean:
$(DEL) *.o *.a *.exe *.dll
ifdef SUBDIRS
$(foreach subdir,$(SUBDIRS),cd $(subdir) && $(MAKE) clean && cd ../ &&) cd ./
endif
int subFunc1();
int subFunc2();
/ComplexCProject
- main.cpp, aaa.cpp
- makefile
- makefile_config
- subStaticModuleA/
- subA1.cpp, subA2.cpp
- makefile
- subDynamicModuleB/
- subB1.cpp, subB2.cpp
- makefile
MyCProject/
- main.cpp
HOST> ssh [email protected]
PI> cd MyCProject
PI> gcc -g3 main.cpp
PI> ./a.out
HOST> ssh [email protected]
PI> cd MyCProject
PI> gdb ./a.out
(gdb) b main
(gdb) run
(gdb) n
(gdb) n
PI> cd
PI> wget -P ~ git.io/.gdbinit
PI> cd MyCProject
PI> gdb ./a.out
>>> b main
>>> run
>>> p i
>>> p i = 9
PI_1> tty # ターミナル1でターミナル名を確認
/dev/pts/1
PI_0> gdb ./a.out # ターミナル0でgdb起動
>>> dashboard -output /dev/pts/1 # 出力先を↑で確認したターミナルに切り替える
>>> b main
>>> run
/ComplexCProject
- main.cpp, aaa.cpp
- makefile
- makefile_config
- subStaticModuleA/
- subA1.cpp, subA2.cpp
- makefile
- subDynamicModuleB/
- subB1.cpp, subB2.cpp
- makefile
HOST> ssh [email protected]
PI> cd MyCProject
PI> gdb ./a.out
(gdb) b main
(gdb) run
(gdb) n
(gdb) n
PI> cd
PI> wget -P ~ git.io/.gdbinit
PI> cd MyCProject
PI> gdb ./a.out
>>> b main
>>> run
>>> p i
>>> p i = 9
PI_1> tty # ターミナル1でターミナル名を確認
/dev/pts/1
PI_0> gdb ./a.out # ターミナル0でgdb起動
>>> dashboard -output /dev/pts/1 # 出力先を↑で確認したターミナルに切り替える
>>> b main
>>> run
#include <stdio.h>
int main()
{
printf("Hello World\n");
for(int i = 0; i < 10; i++) {
printf("i = %d\n", i);
}
printf("Done\n");
return 0;
}
include ../makefile_config
TARGET = ../libsubModuleB.so
SRCS = subB1.cpp subB2.cpp
INCLUDES = -I./
SUBS =
SUBDIRS =
all: sub_target $(TARGET)
$(TARGET): $(OBJS) $(SUBS)
$(CC) $(LDFLAGS) -shared -fPIC -o $@ $(OBJS) $(SUBS)
.PHONY: sub_target
sub_target:
ifdef SUBDIRS
$(foreach subdir,$(SUBDIRS),cd $(subdir) && $(MAKE) && cd ../ &&) cd ./
endif
.PHONY: clean
clean:
$(DEL) *.o *.a *.exe *.dll
ifdef SUBDIRS
$(foreach subdir,$(SUBDIRS),cd $(subdir) && $(MAKE) clean && cd ../ &&) cd ./
endif
include ../makefile_config
TARGET = subModuleA.a
SRCS = subA1.cpp subA2.cpp
INCLUDES = -I./
SUBS =
SUBDIRS =
all: sub_target $(TARGET)
$(TARGET): $(OBJS) $(SUBS)
$(AR) r $@ $(OBJS) $(SUBS)
.PHONY: sub_target
sub_target:
ifdef SUBDIRS
$(foreach subdir,$(SUBDIRS),cd $(subdir) && $(MAKE) && cd ../ &&) cd ./
endif
.PHONY: clean
clean:
$(DEL) *.o *.a *.exe *.dll
ifdef SUBDIRS
$(foreach subdir,$(SUBDIRS),cd $(subdir) && $(MAKE) clean && cd ../ &&) cd ./
endif
include makefile_config
TARGET = a.out
SRCS = main.cpp aaa.cpp
SUBDIRS = subStaticModuleA subDynamicModuleB
INCLUDES += -I./ -IsubStaticModuleA -IsubDynamicModuleB
SUBS = subStaticModuleA/subModuleA.a
LIBS += -L./ -lsubModuleB
all: sub_target $(TARGET)
$(TARGET): $(OBJS) $(SUBS)
$(CC) $(LDFLAGS) -o $@ $(OBJS) $(SUBS) $(LIBS)
.PHONY: sub_target
sub_target:
ifdef SUBDIRS
$(foreach subdir,$(SUBDIRS),cd $(subdir) && $(MAKE) && cd ../ &&) cd ./
endif
.PHONY: clean
clean:
$(DEL) *.o *.a *.exe *.dll *.so *.out
ifdef SUBDIRS
$(foreach subdir,$(SUBDIRS),cd $(subdir) && $(MAKE) clean && cd ../ &&) cd ./
endif
## environment
#PLATFORM = WIN_MINGW
PLATFORM = LINUX
BINARY = DEBUG
#BINARY = RELEASE
ifeq ($(PLATFORM), WIN_MINGW)
# for win
MAKE = mingw32-make
#DEL = del
DEL = rm -f
CC = g++
AR = ar
else
# for linux
MAKE = make
DEL = rm -f
CC = g++
AR = ar
endif
ifeq ($(BINARY), DEBUG)
CFLAGS = -g3 -O0 -Wall
else
CFLAGS = -O3 -Wall
endif
LDFLAGS =
LIBS = -lm
OBJS = $(SRCS:.cpp=.o)
#OBJS = *.o
.c.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $<
.cpp.o:
$(CC) $(CFLAGS) $(INCLUDES) -c $<
#include <stdio.h>
int main()
{
printf("Hello World\n");
for(int i = 0; i < 10; i++) {
printf("i = %d\n", i);
}
printf("Done\n");
return 0;
}
MyCProject/
- main.cpp
{
"host": "192.168.1.88",
"port": 22,
"username": "pi",
"password": "rasp",
"protocol": "sftp",
"agent": null,
"privateKeyPath": null,
"passphrase": null,
"passive": false,
"interactiveAuth": false,
"remotePath": "/home/pi/MyCProject",
"uploadOnSave": true,
"syncMode": "update",
"watcher": {
"files": false,
"autoUpload": false,
"autoDelete": false
},
"ignore": [
"**/.vscode/**",
"**/.git/**",
"**/.DS_Store"
]
}
HOST> ssh [email protected]
PI> cd MyCProject
PI> gcc -g3 main.cpp
PI> ./a.out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment