ValleyBell / MidiConverters

various tools that convert game data into MIDI files
GNU General Public License v2.0
102 stars 14 forks source link

Build docs / makefile? #1

Closed greigs closed 5 years ago

greigs commented 5 years ago

I'm trying to figure out how to build these tools but it would be good to know the parameters for the gcc / g++ command or have a makefile available.

ValleyBell commented 5 years ago

There are no special parameters for GCC/G++ required, unless the readme has a "Compilation note" for it.

In general you can compile tool.c to an executable tool (or tool.exe on Windows) with this line:

gcc tool.c -o tool

There's really nothing else you need.
EDIT: I forgot that with GCC you need to link the maths library (used for pow, sin, etc.) explicitly. Thanks for reminding me:

gcc tool.c -lm -o tool

Maybe I may write a Makefile for them sometime in the future, but I can't make any promises.

greigs commented 5 years ago

Thanks for clarifying. Seems I have something strange with my gcc setup as I was getting errors like the one below, which prompted me to raise this issue. However g++ works just fine. So if in doubt use g++ I guess!

gcc ngp2mid.c -o ngp2mid
/tmp/ccTQdAJE.o: In function `DB2Mid':
ngp2mid.c:(.text+0xe3a): undefined reference to `pow'
ValleyBell commented 5 years ago

ohh, you're right.

GCC needs the math library linked for some functions. (done with -lm) I keep forgetting about that.
I used Visual Studio to develop most of these tool and VS doesn't have the maths library separated from the rest. (I don't have VS project files, because I always just add them temporarily to a generic project.)

greigs commented 5 years ago

Good to know. Whenever I see projects with simple looking .h and .c files I tend to try gcc first in linux, or g++ if I see cpp. It works most of the time. Getting VS setup for anything other than .NET be tricky - lots of things to get wrong without project files.

edit: gcc ngp2mid.c -lm -o ngp2mid works as expected in ubuntu

tcdw commented 3 years ago

Just figured out if you would like to use with WSL (Ubuntu 20.04 LTS), you need to do these:

  1. Clone both this repo and vgmrips/vgmtools
  2. Open WSL. If you haven't installed build-essential, you should install that.
  3. In the directory of this repo, compile anything you want with this command:
gcc <tool name>.c -lm -I. -o <tool name>

This command asks GCC to compile with required headers from vgmrips/vgmtools and math library.

Then, it should works.

ValleyBell commented 3 years ago

Actually, you don't need the vgmtools repo. Instead you change the -I parameter to -I. and it works.

tcdw commented 3 years ago

Actually, you don't need the vgmtools repo. Instead you change the -I parameter to -I. and it works.

Ah, I didn't realize that. Thanks for pointing out!

ValleyBell commented 3 years ago

Sorry, the documentation is really lacking in that regard.