Skip to content

Instantly share code, notes, and snippets.

@apollolm
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apollolm/384b8f5bbaf428535430 to your computer and use it in GitHub Desktop.
Save apollolm/384b8f5bbaf428535430 to your computer and use it in GitHub Desktop.
MapboxGL Native on OSX
Trying to bulid MapboxGL Native on OSX Yosemite.
Following instructions here: https://github.com/mapbox/mapbox-gl-native
When doing this:
brew install pkg-config boost imagemagick
...response was imagemagick is already installed, but not linked.
Ran
brew unlink imagemagick
then `brew install imagemagick` which got me the latest version.
Next, tried to `make osx run-osx`, but kept getting errors:
invalid value 'c++14' in '-std=c++14'
...even though clang and gcc seemed to be up-to date bundled with Xcode.
Eventually, I installed updated Xcode which seemed to magically fix this problem.
Then, the app would open, appear briefly, then error out.
Turns out you need to specify your Mapbox API Key as an environment variable called `MAPBOX_ACCESS_TOKEN`
The instructions in Mapbox's readme tell you to add an environment variable in Xcode, but if running from terminal, do this:
export MAPBOX_ACCESS_TOKEN="sk.eyJ1IjoiYXBvbGxvbG0iLCJhIjoiOC12cmVwWSJ9.w3RcsCbqYEzWaTQM3lZydA"
then:
make run-osx
---------------Getting MapboxGL compiling in QTCreator
Loading mbgl header and cpp files into a single directory called qt.
Trying to compile, getting chrono not found errors.
based on this: http://stackoverflow.com/questions/23134937/qt-creator-on-mac-and-boost-libraries
I added the path to boost include in mapbox-gl-native library to .pro file:
TEMPLATE = app
QT += qml quick widgets
SOURCES += main.cpp \
default_styles.cpp \
glfw_view.cpp \
mainwindow.cpp \
qt_view.cpp
RESOURCES += qml.qrc
macx {
QMAKE_CXXFLAGS += -std=c++11
_BOOST_PATH = /Users/ryanwhitley/Documents/GitHub/mapbox-gl-native/mason_packages/headers/boost/1.57.0
INCLUDEPATH += "$${_BOOST_PATH}/include/"
//LIBS += -L$${_BOOST_PATH}/lib
## Use only one of these:
LIBS += -lboost_chrono-mt -lboost_system # using dynamic lib (not sure if you need that "-mt" at the end or not)
#LIBS += $${_BOOST_PATH}/lib/libboost_chrono-mt.a # using static lib
}
CONFIG += c++14
CONFIG += libc++
LIBS += -stdlib=libc++
QMAKE_CXXFLAGS += -stdlib=libc++
QMAKE_CXXFLAGS += -std=c++14
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
HEADERS += \
mbgl.hpp \
map.hpp \
view.hpp \
chrono.hpp \
constants.hpp \
enum.hpp \
exception.hpp \
geo.hpp \
gl_helper.hpp \
image.hpp \
mat4.hpp \
math.hpp \
noncopyable.hpp \
parsedate.h \
projection.hpp \
ptr.hpp \
recursive_wrapper.hpp \
std.hpp \
string.hpp \
time.hpp \
utf.hpp \
util.hpp \
uv.hpp \
variant.hpp \
variant_io.hpp \
vec.hpp \
environment.hpp \
mode.hpp \
still_image.hpp \
update.hpp \
default_styles.hpp \
log.hpp \
platform.hpp \
glfw_view.hpp \
settings_json.hpp \
qopengl_view.hpp \
gl.hpp \
mainwindow.h \
qt_view.hpp
DISTFILES += \
qmbgl.pro.user
Then change #include <chrono> to #include <boost/chrono.hpp>
Another change that worked was to add this above:
LIBS += -stdlib=libc++
QMAKE_CXXFLAGS += -stdlib=libc++
QMAKE_CXXFLAGS += -std=c++14
This made all of the std::function<> not found and unique_ptr errors go away. from here(https://forum.qt.io/topic/23989/solved-make-qtcreator-qmake-and-clang3-2-work-with-c-11/27)
---Forget that. It's better to build Qt Apps inside of XCode.
The main points to remember when doing this:
* include the Qt 5.4 frameworks QtCore.Framework, QtGui.Framework and QtWidgets.Framework
* Any sample code that #includes <QtMouseEvent> (for example) must be updated to fully qualify the Class to prepend the Framework name, i.e. #includes <QtCore/QtMouseEvent>.
A search thru the Qt install directory /Users/ryanwhitley/Qt/5.4/clang_64/lib will reveal the correct Framework for a given .h or .cpp file.
Next, make sure any custom .h files you've added are included in the Build Steps -> Compile Sources. If this is the case, then the following custom build scripts will be able to find and process the Qt files properly. If not, run MOC manually like this:
Next, it's important to include at least 1 custom build script so that MOC (a Qt Meta Object Compiler?) can convert all of the funky Qt custom syntax into regular .cpp or .h files. (The other script is for .ui files)
To process .h files:
/Users/ryanwhitley/Qt/5.4/clang_64/bin/moc -o ${INPUT_FILE_DIR}/GeneratedFiles/moc_${INPUT_FILE_BASE}.cpp ${INPUT_FILE_PATH}
Output:
${INPUT_FILE_DIR}/GeneratedFiles/moc_${INPUT_FILE_BASE}.cpp
If you have .ui files:
/Users/khan/Qt5.4.0/5.4/clang_64/bin/uic -o ${INPUT_FILE_DIR}/GeneratedFiles/ui_${INPUT_FILE_BASE}.h ${INPUT_FILE_PATH}
Output:
${INPUT_FILE_DIR}/GeneratedFiles/ui_${INPUT_FILE_BASE}.h
These scripts dump to
include/mbgl/platform/default/GeneratedScripts
Make sure to include these in the Build Sources, otherwise you'll get a "vtable reference from XYZ" error when compiling.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment