1

I am trying to use Steamworks SDK and compile it on linux, so I dont have to run it on a more resource intensive windows machine.

To do anything in steamworks you need to use a function SteamAPI_Init() which fails spectacularly when compiling. The below headers, and g++ command are the minimum effective samples of what I am using to try to do this.

#include <unistd.h>
#pragma comment(lib, "libsteam_api.so")

#include "./sdk/public/steam/steam_api.h"
#include <iostream>
#include <stdlib.h>

int main(){
    return SteamAPI_Init();
}

g++ -L./ -llibsteam_api.so File.cpp -o output_file -> throws error cannot find -llibsteam_api.so

g++ File.cpp -o output_file -> (below error)

/usr/bin/ld: /tmp/cc1ozUAl.o: in function `main':
file.cpp:(.text+0x9): undefined reference to `SteamAPI_Init'
collect2: error: ld returned 1 exit status

This compiles just fine on windows (if I change the top 2 lines to be the windows equivalent header and library). I suspect that this has to do with the library that I am trying to use, its a 64 bit version but does the same with the 32 bit version. Otherwise I might be missing some dependency that I couldn't find in the docs

How can I get this to compile properly?

  • `-L` expects a directory, not a file. Did you even consider to read the [documentation of those flags](https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html)? – πάντα ῥεῖ Dec 26 '20 at 23:05
  • -L *was* given a directory `g++ -L./` ? @πάνταῥεῖ –  Dec 26 '20 at 23:16
  • You also cannot link directly to a `.so` file. You nned the appropriate stub (`.a` file) for compile time linkage. The `.so` must be available at runtime. – πάντα ῥεῖ Dec 26 '20 at 23:18
  • Maybe I do not quite understand what steamworksSDK is trying to do with this, they provide the `.so` files but no `.a` files, and all of the header files. I was assuming this .so was the same as a `.lib` (which was needed to compile on windows) as it would provide (I think they're called symbols?) and allow me to use the function. Am I missing something about the functionality of the SDK (https://partner.steamgames.com/doc/api/steam_api#SteamAPI_Init)? or something about compiling this? –  Dec 26 '20 at 23:25
  • Hmm, maybe this helps: https://stackoverflow.com/questions/27208932/link-so-file-to-cpp-file-via-g-compiling – πάντα ῥεῖ Dec 26 '20 at 23:28
  • For some reason, it started working when I moved it from my current working directory, into root, then used `g++ -L/ -l:libsteam_api.so` but, unless g++ has some sort of quirk, I dont see why it didnt work while in the *same* directory (previously libsteam_api.so and file.cpp were in the same directory) –  Dec 26 '20 at 23:37
  • I am pretty sure that 1. GCC doesn't have a _"quirk"_ 2. that it's extremely unlikely that the SDK installs it's `.so` file in the root directory `/`. Just specify the directory where you find those `.so` files with the `-L` option. – πάντα ῥεῖ Dec 26 '20 at 23:39
  • 1
    The SDK is not installed, its just a collection of headers and libraries in folders, Its precompiled as well. I manually moved the file somewhere, it worked. which doesn't make much sense, hence why I called it a "quirk", that's not how its supposed to behave. Even trying now, it works every time even in the same directory. Maybe something strange the machine I'm working with. learned something new at least. Thanks for the help, though, much appreciated. –  Dec 26 '20 at 23:46

0 Answers0