Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build on Mac #27

Closed
zodiac1214 opened this issue Dec 26, 2021 · 14 comments
Closed

Build on Mac #27

zodiac1214 opened this issue Dec 26, 2021 · 14 comments

Comments

@zodiac1214
Copy link

Hi there,

How can i build this on mac? i tried to play with the makefile but i am getting some errors.

TERM='dumb' clang -I ./plugin/xpl -fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=$WORK/b001=/tmp/go-build -gno-record-gcc-switches -fno-common -o $WORK/b001/_cgo_.o $WORK/b001/_cgo_main.o $WORK/b001/_x001.o $WORK/b001/_x002.o -g -O2 -shared
# command-line-arguments
Undefined symbols for architecture x86_64:
  "_XPLMCreateFlightLoop", referenced from:
      __cgo_a29d78a6c750_Cfunc_XPLMCreateFlightLoop in _x002.o
     (maybe you meant: __cgo_a29d78a6c750_Cfunc_XPLMCreateFlightLoop)
  "_XPLMDebugString", referenced from:
      __cgo_a29d78a6c750_Cfunc_XPLMDebugString in _x002.o
     (maybe you meant: __cgo_a29d78a6c750_Cfunc_XPLMDebugString)
  "_XPLMFindDataRef", referenced from:
      __cgo_a29d78a6c750_Cfunc_XPLMFindDataRef in _x002.o
     (maybe you meant: __cgo_a29d78a6c750_Cfunc_XPLMFindDataRef)
  "_XPLMFindPluginBySignature", referenced from:
      __cgo_a29d78a6c750_Cfunc_XPLMFindPluginBySignature in _x002.o
     (maybe you meant: __cgo_a29d78a6c750_Cfunc_XPLMFindPluginBySignature)
  "_XPLMGetDataf", referenced from:
      __cgo_a29d78a6c750_Cfunc_XPLMGetDataf in _x002.o
     (maybe you meant: __cgo_a29d78a6c750_Cfunc_XPLMGetDataf)
  "_XPLMGetDatai", referenced from:
      __cgo_a29d78a6c750_Cfunc_XPLMGetDatai in _x002.o
     (maybe you meant: __cgo_a29d78a6c750_Cfunc_XPLMGetDatai)
  "_XPLMGetDatavf", referenced from:
      __cgo_a29d78a6c750_Cfunc_XPLMGetDatavf in _x002.o
     (maybe you meant: __cgo_a29d78a6c750_Cfunc_XPLMGetDatavf)
  "_XPLMGetDatavi", referenced from:
      __cgo_a29d78a6c750_Cfunc_XPLMGetDatavi in _x002.o
     (maybe you meant: __cgo_a29d78a6c750_Cfunc_XPLMGetDatavi)
  "_XPLMRegisterDataAccessor", referenced from:
      __cgo_a29d78a6c750_Cfunc_XPLMRegisterDataAccessor in _x002.o
     (maybe you meant: __cgo_a29d78a6c750_Cfunc_XPLMRegisterDataAccessor)
  "_XPLMScheduleFlightLoop", referenced from:
      __cgo_a29d78a6c750_Cfunc_XPLMScheduleFlightLoop in _x002.o
     (maybe you meant: __cgo_a29d78a6c750_Cfunc_XPLMScheduleFlightLoop)
  "_XPLMSendMessageToPlugin", referenced from:
      __cgo_a29d78a6c750_Cfunc_XPLMSendMessageToPlugin in _x002.o
     (maybe you meant: __cgo_a29d78a6c750_Cfunc_XPLMSendMessageToPlugin)
  "_XPLMSetDatai", referenced from:
      __cgo_a29d78a6c750_Cfunc_XPLMSetDatai in _x002.o
     (maybe you meant: __cgo_a29d78a6c750_Cfunc_XPLMSetDatai)
  "_XPLMSetDatavi", referenced from:
      __cgo_a29d78a6c750_Cfunc_XPLMSetDatavi in _x002.o
     (maybe you meant: __cgo_a29d78a6c750_Cfunc_XPLMSetDatavi)
  "_XPLMUnregisterDataAccessor", referenced from:
      __cgo_a29d78a6c750_Cfunc_XPLMUnregisterDataAccessor in _x002.o
     (maybe you meant: __cgo_a29d78a6c750_Cfunc_XPLMUnregisterDataAccessor)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
$(xpl): plugin/*.go plugin/xpl/*.go
	GOOS=darwin \
	GOARCH=amd64 \
	CGO_ENABLED=1 \
	CGO_CFLAGS="-I/Users/dzou/Downloads/SDK/CHeaders -DAPL=1 -DIBM=0 -DLIN=0" \
	go build -x -buildmode c-shared -o lin.xpl plugin/xpl/main.go 
@zodiac1214
Copy link
Author

I think i figured it out:

diff --git a/Makefile b/Makefile
index 3ea3f9f..09a7c14 100644
--- a/Makefile
+++ b/Makefile
@@ -40,6 +40,12 @@ $(xplwin): plugin/*.go plugin/xpl/*.go
        CC=x86_64-w64-mingw32-gcc \
        CXX=x86_64-w64-mingw32-g++ \
        go build -x -buildmode c-shared -o $(xplwin) plugin/xpl/main.go
+       GOOS=darwin \
+       GOARCH=amd64 \
+       CGO_ENABLED=1 \
+       CGO_CFLAGS="-I/Users/dzou/Downloads/SDK/CHeaders -DAPL=1 -DIBM=0 -DLIN=0 -DXPLM210=1 " \
+       CGO_LDFLAGS="-F/System/Library/Frameworks/ -F/Users/dzou/Downloads/SDK/Libraries/Mac -framework XPLM" \
+       go build -buildmode c-shared -o mac.xpl plugin/xpl/main.go

zodiac1214 pushed a commit to zodiac1214/atr-xplane that referenced this issue Dec 27, 2021
@maxhille
Copy link
Owner

maxhille commented Jan 4, 2022

Ignoring the PR right now, can you tell me how important having the plugin written in Go is for you? Ie. are you more interested in doing Go-pluing stuff or in having an ATR for X-Plane?

I am asking because I was searching for contributors on the org-forums and it seemed like people were a bit thrown off by not using Lua. So I thought maybe just doing the code in Lua (until we run into performance issues) from https://github.com/X-Plane/XLua

Having actual contributors is more important to me than technicalities so I value your opinion. Doing such a huge project alone is a bit much for me so I am really happy for everyone who wants to help.

@zodiac1214
Copy link
Author

Thanks for getting back to me.

  1. My pr is really just to show how I managed to build on Mac lol, there are tons of improvement for sure (like gh action to download SDK and link that way instead of hard code path)

  2. Speaking of go vs lua vs c/c++ vs whatever out there:

It is getting into those stupid holy war territory. But here are my two cents

From my own experience, hiring people especially new grads in this industry, no kids want to do c/c++ or even java! Everyone likes Python/nodejs/Ruby on rails/go/rust. What does that mean for sim?

A) of course c/c++ is faster (since lua is essentially c when it runs/compiled) but I'd argue assembly is a lot more faster. Why you use c? Because it is easier. Same goes to golang. Let's say c/c++ is 20 times faster than go, but who really cares 1ms vs 20ms when your hardware is so much better.

B) what is going to happen with next generation developers? Unfortunately, I am seeing a lot less C/C++ developers these days. And I think having go is going to open doors to more people (I forked/modified that goplane project in my xairline org lol)

C) using STKP/volanta as examples, why we didn't have these tools before? These are examples how web technologies are bringing more developers to the sim world. I built xairline ui in 2 days. There is no way I can do that in c/c++ in 2 month……

  1. I do want an ATR on mac lol

@maxhille
Copy link
Owner

maxhille commented Jan 5, 2022

As for the PR: No worries, every incremental improvement is fine. It will never be perfecly complete anyways ;-)

WRT Lua maybe you misunderstood me: I am pretty sure using XLua is worse performance-wise as it does not support doing plugin work on a different thread, effectively blocking the simulators main thread. That is why I initially started with Go. On the org-forum there is a guy who has already done a lot of work for an ATR custom engine and he would be willing to share/incorporate the code into this project, but it is all in Lua.

@zodiac1214
Copy link
Author

oh, i know what you mean. And my other reason for using something like go is because go routine :) we are totally on the same page. Lua would work, if one understands how to program it async or using event loop so non critical compute is not blocking the main thread ....

my comment was mainly to share my take on using modern programming language/framework :)

@zodiac1214
Copy link
Author

@maxhille you mentioned that there is some limitation on cgo which causes xplane to crash sometimes when recompilie go plugin. can you share more information on that? I'd really want to look into that and hopefully find some solutions around it

@maxhille
Copy link
Owner

maxhille commented Jan 9, 2022

IIRC it went down to this issue: golang/go#11100

@zodiac1214
Copy link
Author

Hmm, if that's the problem then I am a bit worried to use go for "global" plugin. When you switch planes, it gets reloaded (?) Which will crash xplane potentially…for a plane plugin, it might be OK unless you change plane back and forth?

@maxhille
Copy link
Owner

Maybe try it out yourself. I think this problem only applies while doing dev work. Reloading an unchanged shared library is not a problem IIRC.

I can take a look at this in February as I will have time to work on this this.

But in general you see that using Go for X-Plane plugins is a subject for itself. That is why I would propose using XLua for now to get the Plane itself forward. In general Go indeed is viable for this. I and some other people successfully used https://git.sr.ht/~mh/xp2ts (also by me) back when we still needed that as a workaround and there were no troubles. It is a session plugin.

@zodiac1214
Copy link
Author

Thanks! I will give it a try. I have been looking in your repo for reference :)

@zodiac1214
Copy link
Author

so i tried with a global plugin, when you switch planes, it won't reload so it is not a problem :)

@maxhille
Copy link
Owner

I plan to work a bit on the plane this month. I wonder whether you are also interesting in improving it. In case yes we should probably coordinate a bit. Maybe make a meeting?

@zodiac1214
Copy link
Author

I plan to work a bit on the plane this month. I wonder whether you are also interesting in improving it. In case yes we should probably coordinate a bit. Maybe make a meeting?

i am super busy for the next 3 weeks because of a major release at work :( and we all know that 3 weeks might actually mean 3months..... But i'd keep an eye on this project in case there is any low hanging fruit i can pick

@maxhille
Copy link
Owner

maxhille commented Apr 7, 2022

I changed the plugin architecture to use XLua for now. I think you can close the PR. Maybe we will get back to using go in the future.

@maxhille maxhille closed this as completed Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants