Why does running the UNIX "curl" command from within MATLAB result in an error?

42 views (last 30 days)
Using the "curl" command within MATLAB's "system" function may cause an error such as the following:
>> [A,cURL_out] = system('curl http://www.google.com')
A = 
133 
cURL_out = 
dyld: Library not loaded: /opt/local/lib/libcurl.4.dylib 
Referenced from: /opt/local/bin/curl 
Reason: Incompatible library version: curl requires version 8.0.0 or 
later, but libcurl.4.dylib provides version 7.0.0
Another possible error is:
>> [A,cURL_out] = system('curl http://www.google.com')
A = 
133 
cURL_out =
curl: /usr/local/MATLAB/R2012a/bin/glnx86/libcurl.so.4: no version information available
(required by curl)
curl: (48) An unknown option was passed in to libcurl

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 22 Oct 2021
Edited: MathWorks Support Team on 26 Oct 2021
The reason for this error is that MATLAB ships with its own “libcurl” file ("libcurl.so.4" on Linux and "libcurl.4.dylib" on macOS), which is incompatible with the system's “curl”.
This can be resolved by including the system's native "libcurl" library on the “LD_LIBRARY_PATH” environment variable (on Linux), or the "DYLD_LIBRARY_PATH" environment variable (on macOS). This variable is used by MATLAB to find shared libraries at runtime. Apply the following steps:
1)  First, find where the “curl” binary is located on your system by executing this command from a terminal:
$ which curl
2) Next, find the location of the compatible “libcurl” library for this "curl" command using the following command in the terminal:
$ ldd CURL_PATH
where "CURL_PATH" is the path found in step 1. You can alternatively run the following command, if it is available on your system:
$ otool -L CURL_PATH
The output of the above command will provide a list of libraries used by the "curl" command and the locations of these libraries. Please note the location of the "libcurl.so.4" or “libcurl.4.dylib” file, on Linux and macOS, respectively. Note, to more easily find this library, try piping the output of the above command to the “grep” command like so: “ldd CURL_PATH | grep libcurl”.
3) Start MATLAB.
4) In MATLAB, set the “LD_LIBRARY_PATH” (Linux) or "DYLD_LIBRARY_PATH" (macOS) environment variable to include the location of "libcurl" found in step 2 (call this location LIBCURL_PATH) like so:
>> path1 = getenv('LD_LIBRARY_PATH') % Store existing path
>> path = [LIBCURL_PATH ':' path1] % Add compatible libcurl to path
>> setenv('LD_LIBRARY_PATH', path) % Set the path
You should now be able to use the “curl” command from within MATLAB. Please note that the environment variable changes made in step 4 will go away once you exit MATLAB. To retain these changes between MATLAB sessions, place the 3 lines of code in step 4 into MATLAB’s startup.m file. For more information about this file, please refer to the following link:

More Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Products


Release

R2013b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!