I have modified some code from ARToolkit in MacOS and now I need to compile it with Windows subsystem (Ubuntu). I have followed the ARToolkit user manual instruction and have installed all libraries to compile with Ubuntu.

Here's my makefile :

INC_DIR= ../../include
LIB_DIR= ../../lib

LIBS= $(shell pkg-config --libs opencv) -lARgsub -lARvideo -lAR -framework GLUT -framework OpenGL -framework CoreFoundation 
CFLAG= $(shell pkg-config --cflags opencv) -O -I$(INC_DIR) -Wno-deprecated-declarations 

OBJS = SOIL2/SOIL2.o SOIL2/etc1_utils.o SOIL2/image_DXT.o SOIL2/image_helper.o

all: $(BIN_DIR)/simple $(BIN_DIR)/simple2

$(BIN_DIR)/simple: simple.o $(OBJS)
    ${CC} -o $(BIN_DIR)/simple simple.o $(OBJS) $(LDFLAG) $(LIBS)

$(BIN_DIR)/simple2: simple2.o $(OBJS)
    ${CC} -o $(BIN_DIR)/simple2 simple2.o $(OBJS) $(LDFLAG) $(LIBS)

simple.o: simple.c $(HEADDERS)
    ${CC} $(CFLAG) -c simple.c

simple2.o: simple2.c $(HEADDERS)
    ${CC} $(CFLAG) -c simple2.c

    rm -f *.o
    rm -f $(BIN_DIR)/simple
    rm -f $(BIN_DIR)/simple2

    rm -f *.o
    rm -f $(BIN_DIR)/simple
    rm -f $(BIN_DIR)/simple2
    rm -f Makefile

Now that I can compile using makefile successfully, when I try to run my program I encountered error :

./simple: cannot execute binary file: Exec format error

Then I checked with file command :

Mach-O 64-bit x86_64 executable, flags:<NOUNDEFS|DYLDLINK|TWOLEVEL|PIE>

And my machine is this :

Linux Raisa 4.4.0-17134-Microsoft #285-Microsoft Thu Aug 30 17:31:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux

And I also have read posts here :

  1. Can I run a binary file that is Mach-O executable i386 on linux? (asked in 2010)
  2. What are the alternatives for running a Mach-O 64-bit binary file on a linux machine? (asked in 2017)

and basically both of them stated that there's really nothing we can do about it. Does this still apply ? This is the first time I need to switch between OS when compiling a program, and I'm not familiar with this. If I should edit part which specific part I need to modify ?

  • 1
    Welcome to Ask Ubuntu! If you have the source code of the program, configure it for your system and rebuild for it. That’s all we can tell generally. To get specific advice, could you share your Makefile, for example?
    – Melebius
    Apr 9 '19 at 6:35
  • @Melebius hi, I've updated my question and added my makefile. Would you please take a look at it. Thanks
    – raisa_
    Apr 9 '19 at 6:38
  • 1
    Does your cc point to a non-native compiler? what does type -a cc say? Apr 9 '19 at 9:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.