Well, done that, don’t working. I believe it’s because of the cpp files somehow not being imported correctly when including header files.
I’ve created an script that copies all the source files. It’s placed in dependencies
and called buildmx.sh
:
#!/usr/bin/env bash
rm -rf ../../include/mx/
mkdir ../../include/mx/
echo "🚚 Copying header files..."
cp -R ../mx/Sourcecode/include/mx/api/* ../../include/mx/
echo "🚚 Copying mx/api files..."
cp -R ../mx/Sourcecode/private/mx/api/* ../../include/mx/
echo "🚚 Copying mx/ezxml files..."
cp -R ../mx/Sourcecode/private/mx/ezxml/src/include/ezxml/* ../../include/mx/
cp -R ../mx/Sourcecode/private/mx/ezxml/src/private/private/* ../../include/mx/
echo "🚚 Copying mx/core files..."
cp -R ../mx/Sourcecode/private/mx/core/elements/* ../../include/mx/
cp -R ../mx/Sourcecode/private/mx/core/* ../../include/mx/
rm -rf ../../include/mx/elements
echo "🚚 Copying mx/impl files..."
cp -R ../mx/Sourcecode/private/mx/impl/* ../../include/mx/
echo "🚚 Copying mx/utility files..."
cp -R ../mx/Sourcecode/private/mx/utility/* ../../include/mx/
Then I have check-dependencies.py
on the root of the project:
import os
import subprocess
import sys
print("Checking if MX is available...")
mx_dir = "./include/mx"
buildmx_dir = './dependencies/buildmx.sh'
if not os.path.exists(buildmx_dir):
print("⚠️ buildmx dir doesn't exist.")
sys.exit()
if not os.path.exists(mx_dir):
print("❌ MX not available. Building...")
subprocess.call(['sh', buildmx_dir])
exec(open("./fix-mx-paths.py").read())
else:
print("✅ MX is available")
And fix-mx-paths.py
together with the previous file:
import os
mx_path = './include/mx'
files_list = os.listdir(mx_path)
print("🔃 Fixing compatibility for header files...")
for file in files_list:
print(f" 📝 Patching {file}...", end = '')
# Read the file data
with open(f"{mx_path}/{file}", 'r') as rstream:
filedata = rstream.read()
# Replace all the desired strings
filedata = filedata.replace('mx/api/', '')
filedata = filedata.replace('mx/ezxml/', '')
filedata = filedata.replace('mx/core/elements/', '')
filedata = filedata.replace('mx/core/', '')
filedata = filedata.replace('mx/impl/', '')
filedata = filedata.replace('mx/utility/', '')
filedata = filedata.replace('ezxml/', '')
# Write the changes
with open(f"{mx_path}/{file}", 'w') as wstream:
wstream.write(filedata)
print("ok")
My complete platformio.ini
file ends up being:
[env:esp32doit-devkit-v1]
platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.2idf/platform-espressif32-2.0.2.zip
board = esp32doit-devkit-v1
framework = arduino
build_unflags =
-std=gnu++11
-fno-exceptions
build_flags =
-std=gnu++17
-fexceptions
monitor_speed = 115200
extra_scripts =
pre:./install-dependencies.py
pre:./load_pages.py
pre:./check-dependencies.py
lib_deps =
esphome/AsyncTCP-esphome@^1.2.2
ottowinter/ESPAsyncWebServer-esphome@^2.1.0
ayushsharma82/AsyncElegantOTA@^2.2.6
install-dependencies.py
and load_pages.py
are some scripts for compiling web pages for using in web server.
I’m including the header files and using the example provided by mx in the following file (musicxml.h
):
#include <fstream>
#include "mx/DocumentManager.h"
#include "mx/ScoreData.h"
...
int loadMusic(String path)
{
...
// Once the XML is read, parse it
using namespace mx::api;
// Create a reference to the singleton which holds documents in memory for us
auto &mgr = DocumentManager::getInstance();
std::ifstream istr(path.c_str());
// Ask the document manager to parse the xml into memory for us, returns a document ID.
const auto documentId = mgr.createFromStream(istr);
// Get the structural representation of the score from the document manager
const auto score = mgr.getData(documentId);
// We need to explicitly destroy the document from memory
mgr.destroyDocument(documentId);
if (score.parts.size() != 1)
return LOAD_MUSIC_RESULT_FAIL;
// drill down into the data structure to retrieve the note
const auto &part = score.parts.at(0);
const auto &measure = part.measures.at(0);
const auto &staff = measure.staves.at(0);
const auto &voice = staff.voices.at(0);
const auto ¬e = voice.notes.at(0);
if (note.durationData.durationName != DurationName::whole ||
note.pitchData.step != Step::c)
return LOAD_MUSIC_RESULT_FAIL;
return LOAD_MUSIC_RESULT_OK;
}
However, I get the following error:
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:(.literal._ZN2mx3api15DocumentManager16createFromStreamERSi+0x28): undefined reference to `ezxml::XFactory::makeXDoc()'
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:(.literal._ZN2mx3api15DocumentManager16createFromStreamERSi+0x2c): undefined reference to `mx::core::makeDocument()'
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:(.literal._ZN2mx3api15DocumentManager16createFromStreamERSi+0x34): undefined reference to `mx::core::Document::fromXDoc(std::basic_ostream<char, std::char_traits<char> >&, ezxml::XDoc const&)'
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:(.literal._ZNK2mx3api15DocumentManager7getDataEi+0x4): undefined reference to `mx::core::Document::getChoice() const'
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:(.literal._ZNK2mx3api15DocumentManager7getDataEi+0x8): undefined reference to `mx::core::Document::convertContents()'
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:(.literal._ZNK2mx3api15DocumentManager7getDataEi+0xc): undefined reference to `mx::core::Document::getScorePartwise() const'
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:(.literal._ZNK2mx3api15DocumentManager7getDataEi+0x10): undefined reference to `mx::impl::ScoreReader::ScoreReader(mx::core::ScorePartwise const&)'
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o:(.literal._ZNK2mx3api15DocumentManager7getDataEi+0x14): undefined reference to `mx::impl::ScoreReader::getScoreData() const'
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o: in function `mx::api::DocumentManager::createFromStream(std::basic_istream<char, std::char_traits<char> >&)':
.../include/mx/DocumentManager.cpp:110: undefined reference to `ezxml::XFactory::makeXDoc()'
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .../include/mx/DocumentManager.cpp:112: undefined reference to `mx::core::makeDocument()'
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .../include/mx/DocumentManager.cpp:115: undefined reference to `mx::core::Document::fromXDoc(std::basic_ostream<char, std::char_traits<char> >&, ezxml::XDoc const&)'
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32doit-devkit-v1/src/main.cpp.o: in function `mx::api::DocumentManager::getData(int) const':
.../include/mx/DocumentManager.cpp:194: undefined reference to `mx::core::Document::getChoice() const'
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .../include/mx/DocumentManager.cpp:197: undefined reference to `mx::core::Document::convertContents()'
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .../include/mx/DocumentManager.cpp:200: undefined reference to `mx::core::Document::getScorePartwise() const'
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .../include/mx/DocumentManager.cpp:200: undefined reference to `mx::impl::ScoreReader::ScoreReader(mx::core::ScorePartwise const&)'
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .../include/mx/DocumentManager.cpp:201: undefined reference to `mx::impl::ScoreReader::getScoreData() const'
~/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .../include/mx/DocumentManager.cpp:206: undefined reference to `mx::core::Document::convertContents()'
Hope this helps clearing up what am I doing.
Thanks for the help 