error 126 loading external
I have created an external, working fine in Max for Live on Mac and on the older Windows computer I compiled it on, but on other windows machines I have:
error 126 loading external
From the forum, it seems there's may eb a problem with dll laoding libraries?
It was also created in max 6.1 sdk and the loaded into max 7.05.
any help on this would be really appreciated!
thanks
a quick update, I compiled the externals on windows 7. I just tested compiling simplemsp~ in both max sdk 6.1 and 7.0.3
when loaded on a windows 8 machine, neither work.
The same error appears - (126 loading external)
I spent the morning hunched over no fewer than 3 computers with @Venetian, and we got this worked out. For future reference, here are a few important things to check for developers working in C++, particularly if you're using the C++(11/14) STL.
1. Be sure to define the preprocessor macro MAXAPI_USE_MSCRT before including "ext.h" (if you're lazy or superstitious, just add it to the Preprocessor section of the project properties window). This will ensure that Max doesn't try (and fail) to link to the backward-compatible, but essentially outdated "maxcrt.lib" (which doesn't provide a lot of C++ features).
2. If you don't want the users of your externals to require Microsoft's C++ Redistributable Package for the compiler you're using, compile your objects statically with the \MT flag. Yes, your objects will be unnecessarily larger, but what's a few KB compared to failure to load due to missing dependencies?
3. If you are including , make sure that your function calls to acosh(), asinh(), atanh(), expm1(), exp2(), log2(), round() and trunc() are properly namespaced with std:: .
I think that's what we learned today, hope this helps someone tomorrow...
Jeremy
Thanks very much Jeremy!
to recap what's said above:
The inital error 126 was because I compiled an /MDd build (dynamic use of C runtime library) and in debug. The computer I tested on didn't have this. To get around these, you can statically link in the C runtime library, using Multi-threaded build (/MT), and /MTd or /MDd for debug versions.
1. If you use C++11, you won't want to use Cycling's build of the MicroSoft RunTime library, so in Visual Studio, Property Pages->Preprocessor (for the main external) set a flag "MAXAPI_USE_MSCRT" and hit apply/okay so every file uses this flag.
2. In Linker, you should delete libcmt.lib from being ignored - as you would want these two libcmt.lib and libcmtd.lib
3. For C++ code, in C/C++->advanced, you would compile as C++ for all bar the .c files.
If you get an Error 127 you could try building with Max 6 sdk. As above uses of round(), trunc(), atanh() etc should be calling the std:: library versions.
I need to correct your final point. The Max 6 vs. Max 7 SDK makes no difference. The difference was that your Max 6 SDK project didn't link to the jitlib.lib, whereas your Max 7 SDK project did. If you link to the jitlib.lib (with whichever SDK), you will need to explicitly use the std:: namespace for those functions, but you should be using namespace std anyway! :-)
great info Jeremy, thanks alot
Jeremy, you are my Max hero
For posterity though, I tried adding MAXAPI_USE_MSCRT to my preprocessor (I'm superstitious), and this caused this particular problem to mutate into an error 193--external not built for Windows. However, making sure to define MAXAPI_USE_MSCRT before importing ext.h seems to have fixed things.
Hey, I'm not super techy, so if you could explain how you fixed this in simple terms that would be great. I tried downloading beat~, pitch~, and segment~, and they all get the same error 126 message.
I followed Jeremy's and Venetian's directions but am now getting the error message:
Error 1 error LNK2005: sprintf already defined in MaxAPI.lib(MaxAPI.dll) L:\Code\DSP\platform\MaxMSP\audio\elvis3~\LIBCMTD.lib(sprintf.obj)
Thanks for any suggestions,
Sukandar
p.s. also, judging by how often this problem shows up on the forum, it would be cool if C74 could address this "error 126" issue in the developer documentation. I just downloaded the latest 8.x SDK and MaxAPI.pdf still has a timestamp from 2015.
good luck!
Im guessing here but
Sprintf is a C function?
Us that called by your external?
How are the includes looking?
thanks for the reply, Venetian
yes, sprintf() is used
not by anything particular to my code, but by the _assist() function that I inherited from the example code
I include these:
#include "ext.h"
#include "ext_buffer.h"
#include "ext_obex.h"
#include "z_dsp.h"
You could have a look at Max Devkit?
https://github.com/Cycling74/max-devkit
It uses Cmake to build three example projects that compile c++ externals. When I returned to my project recently Iysed that and found it very good.
thanks, I'll have a look
I should clarify though that I'm not actually trying to get C++ working. I'm doing plain old C here.
I get both the error 126 + a message that MSVCR120D.dll is missing
Hello everyone
I also had similar problems and many 'errors 126 loading external' when i tried to play application on another computer, and i really tried to follow every step you wrote up there, but i am feeling myself like i have lack of knowledge to follow all. Some parts i don't even know how to do and what they mean.
Is there any chance to someone make video about all this steps from above? It would be really awesome, i guess it would be easier to follow these instructions to me and people who are still new in Max as i am.
Sorry if i'm asking for too much, i would just really appreciate if it would exist
Thank you
you buult an external for a different windows machine?
our notes above relate to linking against static vs dynamic libraries, could you find these in visual studio’s build settings?
Hi Venetian, thanks for reply,
I built application on my windows 10 machine and tried to open it on another windows 10 machine, but then i have few errors which are 'error 126 loading external'. I tried to include manually inside of build script (application) all of the files i used inside of patch, but again same errors appear when i try to play it on another windows device.
I found in visual studio settings your 1. and 2. step and i changed everything as you mentioned above, instead of 3. step which i really didn't understand.
But however, same errors with externals appear even after changing settings. What am i doing wrong?
@Lazmih I wonder if you could run through what you're doing in detail? Presumably compiling an external you've written on windows and moving to another machine? Is it C or C++?
I would suggest separating the parts. Try compiling MySimpleMax external on your machine and move this. If this is working, we know that the settings there are working for you.
a couple of points from Jeremy, maybe he has something to say here?
2. If you don't want the users of your externals to require Microsoft's C++ Redistributable Package for the compiler you're using, compile your objects statically with the \MT flag. Yes, your objects will be unnecessarily larger, but what's a few KB compared to failure to load due to missing dependencies?
This seems a bit complicated to me but is to do with static vs dynamic linking for Windows. Are you using C++?
If so, what about my max-dev-kit suggestion. Tim Place wrote something on that. It seems that it's a very easy way to compile an external and is a Cycling74 official(ish) release.
3. If you are including , make sure that your function calls to acosh(), asinh(), atanh(), expm1(), exp2(), log2(), round() and trunc() are properly namespaced with std:: .
This is a bit of a weird one. for some reason, there are other functions called round and trunc that aren't std::round. Try building an external without any math functions first and then add these in.
I'd be interested to hear from Cycling74 people on this, but I really like the new max-dev-kit way of doing externals:
https://github.com/Cycling74/max-devkit
(there's a nice way to build a project with CMake and perhaps it will take care of some of these things)
how does this relate to the older Max-SDK?
Hey ! Sorry to add up something after all this time. Though I have the same problem and I'm quite in a rush. I've given a quick try to max-devkit but Visual Studio can't compile and I'm sure I will spend a lot of time (again) to make it work. So I use the Max SDK and I get the error
error 126 loading external
So I want to use the sndfile library and I tried to use both MDd and MTd options, added MAXAPI_USE_MSCRT in my preprocessor options, deleted all the calls to round and all that functions and deleted libcmt.lib from being ignored. I still get the error.
What can I do next?
Are you writing C++ code? Is the standard library involved?
eg are you calling any functions such as acosh(), asinh(), atanh(), expm1(), exp2(), log2(), round() and trunc()
these could be problematic (does namespacing such as std::trunc help?)
In practice, I used a workaround, an alternative function for round called rounder() that returns a rounded double. It seems strange to be avoiding std library STL code, but this might help.
My problem I didn't put the .lib file in the resource/support file. I should do a little tuto about all that because there is not much explanations out there about that.
I think that max devkit: https://github.com/Cycling74/max-devkit
and min devkit: https://github.com/Cycling74/min-devkit
could be very useful for developing externals, particularly those which want to integrate modern C++.
I'd be curious to know from Tim Place and the Cycling 74 team:
Are these Windows bugs regarding use of STL library: see Jeremy's comment above regarding use of std::round, std::truc and so on, still an issue?
Hi,
I've been developing externals with Min-DevKit almost exclusively for the last 3 or 4 years and have not run into problems using std::round() and friends.
The traditional Max SDK is very exposed to name conflicts and such as it is not C++ savvy with regards to namespacing.
Cheers!
Tim
oh, that sounds promising. So do you think a Windows external built with max-devkit and / or min-devkit would be able to use namespaced std::floor, std::round, std::trunc ect fine these days?
Jeremy and I had some problems a few years back when compiled on one machine for Windows and loaded on another.
There could be any number of things going on there. The default for linking with Min-DevKit (and probably Max-DevKit?) is to use static libs for the C/C++ runtime on Windows which should alleviate that type of issue.
Hi there,
I'm a bit sorry to dig out that post after a whole year, but I'm encountering the same problem and thought it would be more constructive than creating a whole new post. For the context, I'm using a customized version of the structure of the max-sdk, adapted to CMake with the CMakeLists.txt being straight-up the ones from the max-devkit, adapted to the structure and content of the max-sdk. I'm working in C, not in C++, so the use of the min-devkit is excluded. The compiler I'm using is MSVC2019 for Max/MSP 8. I'm able to compile working Max and MSP examples (and I'm not using Jit).
My code compiles my ~.mxe64 files without errors, and said externals work fine on some computers, but return an error 126 on some others. I can't find a common denominator: all computers have the latest version of MSVC Redist 2015-2019 installed, and the /MT argument is passed to the compiler, which I think should rule out that error entirely. I also tried using the /MD argument instead, as well as to add the various MSVC Redist 2019 DLL to the Max 8 executable location, to no avail. I even checked the Max/MSP File Preferences and a number of other things, still no idea about what's happening.
If necessary, I can provide the CMakeLists.txt files and structure so you can have an overview of the project. They're basically the same as the ones from the max-devkit, however, and no compilation option has been modified.
Any help would be hugely appreciated.
@Leo I do sympathise if you're writing here. I would simplify things. As i understand it, you compile C code, and you hit an error: "error 126 loading external" on Windows only and some machines only?
Can you start out by building simplemsp~ and work up to your external?
The question I have. Jeremy discovered a conflict with the C++ STD library. But is there such a thing in C?
sprintf is mentioned above. Could you try to simplify the external to check build problems? Or another way to discern between your CMakeList question and the actual compiled code?
First of all, thank you for this fast answer!
As i understand it, you compile C code, and you hit an error: "error 126 loading external" on Windows only and some machines only?
Precisely. To be thorough, I'm only working on Windows (hence why I posted here, I think Error 126 is related to a Windows dynamic library Max can't find). The strange part is that I'm having this error on some machines only. It might be due to me not building the externals correctly, or some missing component of the machines aforementioned.
Jeremy discovered a conflict with the C++ STD library. But is there such a thing in C?
There is the stdlib, and I believe the conflict to be of a similar nature, or due to Max not finding the correct DLL. I'm not using `sprintf` or consorts, but I'm using `malloc` from "ext.h".
Could you try to simplify the external to check build problems?
The simplest external I can check easily is the [simplemsp~] object. Building it in the context of my project (same toolchain, same CMakeLists structure) works fine, and it loads correctly on a computer on which I encounter the error 126 when I try to load my own modules.
I don't believe I can simplify one of my own externals any more than I am currently.
Hi, I'd recommend using Dependency Walker to determine what cannot be loaded on the machines in question. Presumably you need one of the MS Redistributable packages to support some feature you're using, but obviously it would be nice to understand which feature that is, and whether you can reimplement your code without it. Also, feel free to send your source over and I can take a look, as well.
Hi Jeremy,
Thank you for your advice. Indeed, using Dependencies (a newer and more stable equivalent of Dependency Walker) ended up tipping me off for the solution.
My issue wasn't related to Max/MSP nor to my external, after all. Said external depended upon a DLL correctly installed, but that was compiled with GCC and dynamic linked to libgcc, making it mandatory. mingw and the related libgcc weren't installed on the computers encountering the aforementioned error 126. Said error is actually signalling a missing dependency in general, not particularly to MSVC, which initially put me off the trail. I ended up recompiling said DLL with the `-static-libgcc`, which fixed the issue. That's all the fun of using several compilers at once.
Thank you again for the help!
Would it be interesting to some if I committed the template of my project, for new users to be able to use CMake with MSVC in a C environment?
Hi all
In my experience, if you're linking shared third party library, Max will not search dll files on external directory. For example if you copied both external (.mxe or .mxe64 file) and library (.dll) in "Documents/Max 8/Library" folder, you end up error 126 because Max cannot find library file. You must copy them in one of your PATH folders.
I'm using Windows 10 with Max 8 and Max SDK 7.3.3