6

I am trying to run a c++ program on Heroku, I've read this post: How to run an executable on Heroku from node, works locally however I didn't manage to make it work because the server doesn't have g++ on it (or gcc for that matter). I tried downloading g++ onto the server like so sudo apt-get install g++ however I don't have root permissions. Also I tried copying my copy of g++ to the server but my mac has a different architecture than the server so that didn't work either. Clearly this is possible seeing as that it has been solved in the question I linked above however I can't figure out how to do it. Any help is appreciated. Thanks.

Mathew
  • 1,116
  • 5
  • 27
  • 59
  • If you cannot compile it on the target machine, you will need to _cross-compile_ it. – paddy May 31 '18 at 03:15
  • how does one cross-compile? I know that the architecture is: `Linux 4be8fe2c-2655-428c-a4ed-dd011dc871c4 4.4.0-1019-aws #19-Ubuntu SMP Thu May 3 15:08:36 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux` – Mathew May 31 '18 at 03:19
  • Cross-compiling is hard. It may be easier for you to either contact the administrator and ask them to install g++, or spin up your own temporary server instance with the same distribution and architecture in the cloud (or maybe even as a VM on your machine) and compile it there. – paddy May 31 '18 at 04:07
  • I got it working, I have access to a linux machine at my school so I sshed into that, compiled my code there, downloaded it onto my mac, uploaded it onto heroku, and then it worked – Mathew May 31 '18 at 04:30

2 Answers2

9

There are 2 ways you can do this.

Using Heroku's buildpack api, you can setup a buildpack which will compile your code when the app is being built.

There is even a few C buildpacks available: https://github.com/heroku/heroku-buildpack-c

You can also use Docker. Your Dockerfile would build the binary. You could run it locally, then push and release it to Heroku. See https://devcenter.heroku.com/articles/container-registry-and-runtime

Damien MATHIEU
  • 31,924
  • 13
  • 86
  • 94
6

In case there is someone else out there trying to this, I got it to work by compiling it on a linux machine then uploaded the executable to Heroku. So assuming one has access to a linux machine with g++ on it, this should be possible.

Mathew
  • 1,116
  • 5
  • 27
  • 59