ReVorb icon indicating copy to clipboard operation
ReVorb copied to clipboard

Compiling on Linux

Open apocalyptech opened this issue 4 years ago • 2 comments

Hello!

I'm honestly writing this more for informational purposes, in case someone else wants to compile on Linux and wants a few pointers. Getting it compiling on Linux requires a few code changes, and I don't know the best way to make something like this more crossplatform (my C/C++ is extraordinarily rusty). I also wouldn't expect you to support an extra OS or anything, of course. :)

Anyway, this compiles and runs just fine on Linux with a few minor changes:

  1. Case-sensitivity: #include "ReVorb.h" at the top of revorb.cpp needs to be #include "revorb.h" instead (that, or the header file renamed to have the capital letters)
  2. Lack of "safe" C11 Annex K functions (the *_s functions) in glibc/gcc. There's more than one Linux implementation of these out there, but the one I used was https://github.com/rurban/safeclib - this won't be found by default on most Linux machines. After installing/compiling that, add #include <libsafec/safe_lib.h> and #include <libsafec/safe_str_lib.h> to revorb.h
  3. Other header changes: In revorb.h, remove the include for io.h and substitute unistd.h
  4. _unlink doesn't exit -- just change those instances to unlink instead, in revorb.cpp. There's two instances. (This is what unistd.h provides)
  5. Linux doesn't distinguish between text/binary while reading from STDIN, and doesn't have _setmode (or _fileno). Just comment out those lines in revorb.cpp entirely. There's two instances of that. I did verify that reading in the file via stdin produces the same output as from a file.

So, do all that, and it compiles/runs just fine with:

g++ -o revorb -logg -lvorbis -lsafec-3.6.0 revorb.cpp

I'm attaching a patch with all the changes that I mentioned. As I say, not expecting any of this to get merged in or whatever. If I ever get enthusiastic enough to draft up a "proper" PR for this, I'll submit it that way.

revorb_linux.patch.gz

apocalyptech avatar Jun 04 '21 21:06 apocalyptech

Patch inlined for readability, too:

diff --git a/revorb.cpp b/revorb.cpp
index 425f7b5..d1fde84 100644
--- a/revorb.cpp
+++ b/revorb.cpp
@@ -17,7 +17,7 @@
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

-#include "ReVorb.h"
+#include "revorb.h"

 bool Failed = false;

@@ -152,7 +152,7 @@ int32_t main(int32_t argumentCount, const char* arguments[])
     if (!strcmp(arguments[1], "-"))
     {
         fi = stdin;
-        _setmode(_fileno(stdin), _O_BINARY);
+        //_setmode(fileno(stdin), _O_BINARY);
     }
     else
     {
@@ -173,7 +173,7 @@ int32_t main(int32_t argumentCount, const char* arguments[])
         if (!strcmp(arguments[2], "-"))
         {
             fo = stdout;
-            _setmode(_fileno(stdout), _O_BINARY);
+            //_setmode(fileno(stdout), _O_BINARY);
         }
         else
         {
@@ -348,12 +348,12 @@ int32_t main(int32_t argumentCount, const char* arguments[])
     {
         if (Failed)
         {
-            _unlink(tmpName);
+            unlink(tmpName);
             strcat_s(tmpName, sizeof(tmpName), ".tmp");
         }
         else
         {
-            if (_unlink(arguments[1]) || rename(tmpName, arguments[1]))
+            if (unlink(arguments[1]) || rename(tmpName, arguments[1]))
             {
                 fprintf(stderr, "%S: Could not put the output file back in place.\n", tmpName);
             }
diff --git a/revorb.h b/revorb.h
index 0692646..6277d67 100644
--- a/revorb.h
+++ b/revorb.h
@@ -18,10 +18,12 @@
 */
 #pragma once
 #include <stdio.h>
-#include <io.h>
+#include <unistd.h>
 #include <fcntl.h>
 #include <string.h>
 #include <iostream>
+#include <libsafec/safe_lib.h>
+#include <libsafec/safe_str_lib.h>
 #include "libogg/ogg.h"
 #include "libvorbis/codec.h"

apocalyptech avatar Jun 04 '21 21:06 apocalyptech

Thanks for the info! I was planning on rewriting this entire project in modern C++ so it uses std::ofstream and std::filesystem (which would fix a lot of these issues) but got busy with other projects/work. Don't expect myself to do that anytime soon because I'm lazy, but if you do submit a pr I will definitely merge it.

ItsBranK avatar Jun 04 '21 22:06 ItsBranK