How to get a C++ compiler with CircleCI?

I have this basic CI set up, and what it does is it compiles a commit in both Linux and Windows environments. The repository is a C++ project, so I have to make sure any new commits can be compiled using a C++ compiler in both Linux and Windows without error.

version: 2.1

orbs:
  win: circleci/windows@2.2.0

jobs:
  build-for-linux:
    docker: 
      - image: cimg/node:14.10.1
        auth:
          username: mydockerhub-user
          password: $DOCKERHUB_PASSWORD
    steps:
      - checkout
      - run: g++ src/night.cpp
      
  build-for-windows:
    executor:
      name: win/default
      size: "medium"

    steps:
      - checkout
      - run: g++ src/night.cpp

workflows:
  version: 2.1
  build:
    jobs:
      - build-for-linux
      - build-for-windows

Here’s the repository for that. This is actually my first time using CircleCI, so I don’t really know what I’m doing, or if this is the best way to do it.

So when I have a new commit, the Linux build works fine, but the Windows build does not. It says that g++ is not recognized. So is there a way to “install” a C++ compile onto CircleCI so I can compile C++ files?

Thanks

It’s sad that no one has answered this post. I have no i686 Linux machines and my computer can’t make a virtual machine, and I want to test a C++ file in CircleCI like I did in GitLab when I first started using CIs.

2 Likes

Let me check with the team and see if anyone has C++ tips!

Hi @DynamicSquid,

Thanks for your patience.

Right now, you have to install mingw on Windows to have GCC. We preinstall Chocolatey on Windows, so you can use that to install mingw or if you’d rather not install anything, you can use the Visual Studio compiler that’s preinstalled.

1 Like

@thekatertot I installed g++ using Choco and it worked great! I came across a slight problem though. When I tried to compile a file using g++, it says source file can’t be found. So when the CI runs, does it automatically clone the repo?

Here’s what I have so far:

version: 2.1

orbs:
  win: circleci/windows@2.2.0

jobs:
  build:
    executor:
      name: win/default
      shell: powershell.exe
    steps:
      - run:
          name: Installing g++
          command: 'choco install mingw'
      - run:
          name: Compiling Code
          command: 'g++ -std=c++17 -Wall -Werror -o night src/night.cpp'
      - run:
          name: Testing Code
          command: './night tests/test.night'

It gives me an error when compiling code. It says src/night.cpp cannot be found

Oh it worked now just forgot to checkout

1 Like

Let us know if we can help any more :partying_face:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.