Sublime Forum

Linking files (C++) using build system

#1

Having looked at this :

Build Sys Improvement 2017

and

Multiple files for builds 2019

to which there was no answer, I was wondering if it was possible to link object files using the build system.

I can compile using this build system:

{
  "cmd" : ["clang++-3.8 -std=c++14 -stdlib=libc++ -w -c ${file_name}"],
  "selector" : "source.c",
  "shell": true,
  "file_regex":"^(|..[^:]*):([0-9]*):?([0-9]*)?:? (.*)$",
  "working_dir" : "$file_path"
}

but linking is a bit trickier, take this for example:

g++ WLM001.o DeleterTemplates.o sdl_helper.o PS_HelperStructs.o PosterSurface.o GTexture.o -lSDL2 -lSDL2_image -lc++ -lm -lgcc_s -lgcc -lc -o WLM004

The command would be something like:

“cmd” : ["g++ ${file_name0}.o ${file_name1}.o ${file_name2}.o ${file_name3}.o -lSDL2 -lSDL2_image -lc++ -lm -lgcc_s -lc ${some_other_filename}"],

My questions are:

The file_names in bold are wrong, what would be the correct format ?

Is it possible to have a variadic format so that the command argument could take any number of object files as an input, either user defined, open files or all the object files in the directory?

Again some_other_filename in italics is also wrong. What would the correct syntax, to either use an extensionless version of the first file in bold or a user defined input ?

Is any of this possible ?

Am I barking up the wrong tree completely ?

All the best y’all !

Lozminda :unicorn::skull_and_crossbones:

0 Likes

#2

Yes. Use one of CMake, Meson, Bazel, build2, and invoke their central build command from an ST build system.

1 Like

#3

I had a funny feeling. I’ve been putting off CMake and all it’s glory…:smiley:

0 Likes

#4

Regular make will also work; even a shell script or batch file could be used.

Indeed there’s no way to build files other than the current file except to use *.cpp* to grab all files and always compile them all or to use a custom plugin that grabsthe names of other open files, but that way lay madness.

The moral of the story is “right tool for the job”. Don’t use a hammer to put in a screw, don’t use a table saw to slice your bread, and use a dedicated build management tool to manage your builds. :wink:

1 Like

#5

Don’t use a hammer to put in a screw? Clearly you’ve never worked in the UK Construction Industry…

:unicorn::skull_and_crossbones:

Can’t choose two solutions hence @OdatNurd it’s a like…

0 Likes

#6

SDL2 already comes with a cmake package file. So you can use

find_package(SDL2 REQUIRED)
target_link_libraries(WLM004 PRIVATE SDL2::SDL2 SDL2::SDL2image SDL2::SDL2main)
0 Likes

#7

Cool.

Will look into into it. Currently doing some long over due backing up, so while I’m going I best keep going on that.

Thank you !

0 Likes