VScode配置makefile工程(以ucosii在Win32上的应用示例)

一. 目录结构

├─UCOS-II-x86--master
  ├─.vscode
  ├─Doc
  ├─Ports
  │  └─80x86
  │      └─WIN32
  │          └─GCC-MINGW
  │              ├─examples
  │              │  ├─example0
  │              │  ├─example1
  │              │  ├─example2
  │              │  ├─example3
  │              │  ├─example4
  │              │  └─example5
  │              ├─labs
  │              │  └─LabDemo
  │              ├─src
  │              ├─templates
  │              └─utils
  └─Source

二. 编写好makefile文件,试验ok;

1. 根目录下的makefile

all:
	make -C Ports/80x86/WIN32/GCC-MINGW/examples/example0/

2. examples0下的makefile

########## The following definition must be set for uCOS >= V2.8x #############
CC := gcc


########## It must not be set for older versions ##############################
CFLAGS=-DNO_TYPEDEF_OS_FLAGS

########## Path for uCOS-II core source files #################################
UCOS_SRC=../../../../../../source

########## Path for uCOS-II WIN32 port source files ###########################
UCOS_PORT_SRC=../../src

########## Path for uCOS-II WIN32 example source files ########################
UCOS_PORT_EX=$(CURDIR)

########## Path for uCOS-II WIN32 port library file# ##########################
UCOS_PORT_LIB=$(UCOS_PORT_EX)

########## Name of Example source file ########################################
MINGW_LIB=/msys64/mingw64/lib/


EXAMPLE=test

   

all:	$(EXAMPLE).c  app_cfg.h  os_cfg.h  includes.h  $(UCOS_PORT_LIB)/ucos_ii.a makefile
	
	echo "Current directory is: $(CURDIR)"

	@echo --- Recompiling the application ---
	gcc -D__WIN32__ $(CFLAGS) -I$(UCOS_SRC) -I$(UCOS_PORT_SRC) -I$(UCOS_PORT_EX) $(EXAMPLE).c $(UCOS_PORT_LIB)/ucos_ii.a -L$(MINGW_LIB)/libwinmm.a -L$(MINGW_LIB)/libcoldname.a -lwinmm -o $(EXAMPLE).exe

$(UCOS_PORT_LIB)/ucos_ii.a:	os_cfg.h 
	@echo --- Recompiling library ucos_ii.a ---
	gcc -c -D__WIN32__ $(CFLAGS) -I$(UCOS_SRC) -I$(UCOS_PORT_SRC) -I$(UCOS_PORT_EX)  $(UCOS_SRC)/ucos_ii.c $(UCOS_PORT_SRC)/pc.c $(UCOS_PORT_SRC)/os_cpu_c.c 
	@ar -r $(UCOS_PORT_LIB)/ucos_ii.a ucos_ii.o os_cpu_c.o pc.o

clean:
	@rm -f *.o
	@rm -f *.bak

cleanall:
	@rm -f *.o
	@rm -f *.bak
	@rm -f *.a
	@rm -f *.exe
		

三. 设置make编译命令。

    注:前提是设置环境变量PATH: gcc.exe gdb.exe

      1. 修改.vscode 文件夹中task.json :

         (1) 将command由gcc修改为make;

   

{
    "tasks": [
      {
        "type": "cppbuild",
        "label": "C/C++: g++.exe build active file",
        "command": "make" , 
        "args": [],
        "options": {
          "cwd": "${workspaceFolder}"
        },
        "problemMatcher": ["$gcc"],
        "group": {
          "kind": "build",
          "isDefault": true
        },
        "detail": "Task generated by Debugger."
      }
    ],
    "version": "2.0.0"
  }

     注:${workspaceFolder} 表示的是.vscode 目录的上一级目录

        2. 修改.vscode 文件夹中launch.json :

           (1)修改生成(待调试)的目标程序: "program": "${workspaceFolder}\\Ports\\80x86\\WIN32\\GCC-MINGW\\examples\\example0\\test.exe",

           (2)确认调试器:

           "MIMode": "gdb",

          "miDebuggerPath": "gdb.exe",

{
    "configurations": [
      {
        "name": "C/C++: g++.exe build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${workspaceFolder}\\Ports\\80x86\\WIN32\\GCC-MINGW\\examples\\example0\\test.exe",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${fileDirname}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "miDebuggerPath": "gdb.exe", 
        "setupCommands": [
          {
            "description": "Enable pretty-printing for gdb",
            "text": "-enable-pretty-printing",
            "ignoreFailures": true
          },
          {
            "description": "Set Disassembly Flavor to Intel",
            "text": "-gdb-set disassembly-flavor intel",
            "ignoreFailures": true
          }
        ],
        "preLaunchTask": "C/C++: g++.exe build active file"
      }
    ],
    "version": "2.0.0"
  }

 2. 修改.vscode 文件夹中c_cpp_properties.json :

{
    "configurations": [
      {
        "name": "GCC",
        "includePath": ["${workspaceFolder}/**"],
        "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
        "windowsSdkVersion": "10.0.22000.0",
        "compilerPath": "gcc.exe",
        "cStandard": "c17",
        "cppStandard": "c++17",
        "intelliSenseMode": "windows-gcc-x64"
      }
    ],
    "version": 4
  }

四、安装cmake & cmake-converter

1. >  pacman -S --needed base-devel mingw-w64-x86_64-cmake
2. >安装python

3. 利用pip安装cmake-converter,为了避免与pacman安装包冲突,创建一个专门用于python包安装的目录环境:

    (1)$ python3 -m venv /home/guqf/.pyenv

    (2)激活: cd /home/guqf/.pyenv/bin/

                         source activate

      (3) pip install cmake-converter

      

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值