I am running following command:
gcc -DPJ_AUTOCONF=1 -fPIC -DPJ_IS_BIG_ENDIAN=0 -DPJ_IS_LITTLE_ENDIAN=1 -I/usr/local/include -L/usr/local/lib -lpjsua-x86_64-unknown-linux-gnu -lpjsip-ua-x86_64-unknown-linux-gnu -lpjsip-simple-x86_64-unknown-linux-gnu -lpjsip-x86_64-unknown-linux-gnu -lpjmedia-codec-x86_64-unknown-linux-gnu -lpjmedia-videodev-x86_64-unknown-linux-gnu -lpjmedia-x86_64-unknown-linux-gnu -lpjmedia-audiodev-x86_64-unknown-linux-gnu -lpjnath-x86_64-unknown-linux-gnu -lpjlib-util-x86_64-unknown-linux-gnu -lresample-x86_64-unknown-linux-gnu -lmilenage-x86_64-unknown-linux-gnu -lsrtp-x86_64-unknown-linux-gnu -lgsmcodec-x86_64-unknown-linux-gnu -lspeex-x86_64-unknown-linux-gnu -lilbccodec-x86_64-unknown-linux-gnu -lg7221codec-x86_64-unknown-linux-gnu -lportaudio-x86_64-unknown-linux-gnu -lpj-x86_64-unknown-linux-gnu -lm -lnsl -lrt -lpthread -lcrypto -lssl pjsuaCreate.c
The content of pjsuaCreate.c is:
#include <pjsua-lib/pjsua.h>
int main(int argc, char *argv[])
{
pj_status_t status = pjsua_create();
return 0;
}
I am getting:
/tmp/cc7U0i1Q.o: In function `main': pjsuaCreate.c:(.text+0x10): undefined reference to `pjsua_create'
collect2: ld returned 1 exit status
Im on Ubuntu and doing grep shows following:
$ grep -r "pjsua_create" /usr/local/lib/
Binary file /usr/local/lib/python2.7/dist-packages/_pjsua.so matches
Binary file /usr/local/lib/libpjsua-x86_64-unknown-linux-gnu.a matches
Since at least some of the libraries are static (archives), you might be encountering the dependency ordering problem described here.
Enclose the -l<lib1> -l<lib2> ... options between the -Wl,--start-group and -Wl,--end-group options (linker flags) respectively.
Related
I'm using bitbake 1.32.0, Yocto 2.2.2 (Poky) trying to add protobuf-c to my build. I keep getting a build failure on protobuf_2.6.1 (protobuf-c depends on protobuf).
I can manually download the Protobuf source code and cross-compile it without any problems. But for some reason Yocto can't build it.
During the Yocto build process, libprotobuf-lite.so links okay, but libprotobuf.so fails linking due to these errors:
| /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
| /usr/src/debug/glibc/2.24-r0/git/csu/elf-init.c:87: undefined reference to `__init_array_end'
| /usr/src/debug/glibc/2.24-r0/git/csu/elf-init.c:87: undefined reference to `__init_array_start'
| /home/cjholmes/gen4/build/tmp/sysroots/x86_64-linux/usr/libexec/arm-agl-linux-gnueabi/gcc/arm-agl-linux-gnueabi/6.2.0/ld: .libs/libprotobuf.so.9.0.1: hidden symbol `__init_array_end' isn't defined
| /home/cjholmes/gen4/build/tmp/sysroots/x86_64-linux/usr/libexec/arm-agl-linux-gnueabi/gcc/arm-agl-linux-gnueabi/6.2.0/ld: final link failed: Bad value
I have tried looking through the .o files that are part of libprotobuf.so but are not included in libprotobuf-lite.so, to see if anything directly references the missing symbols, but I haven't found anything useful yet.
For a while I thought the culprit was -nostdlib. But then I saw libprotobuf-lite compiles just fine with that flag, and the -lc and -lgcc flags are included in the link command.
The recipe is a very straightforward autotools setup.
SUMMARY = "Protocol Buffers - structured data serialisation mechanism"
DESCRIPTION = "Protocol Buffers are a way of encoding structured data in an \
efficient yet extensible format. Google uses Protocol Buffers for almost \
all of its internal RPC protocols and file formats."
HOMEPAGE = "https://github.com/google/protobuf"
SECTION = "console/tools"
LICENSE = "BSD-3-Clause"
PACKAGE_BEFORE_PN = "${PN}-compiler"
DEPENDS = "zlib"
RDEPENDS_${PN}-compiler = "${PN}"
RDEPENDS_${PN}-dev += "${PN}-compiler"
LIC_FILES_CHKSUM =
"file://LICENSE;md5=af6809583bfde9a31595a58bb4a24514"
SRCREV = "bba83652e1be610bdb7ee1566ad18346d98b843c"
PV = "2.6.1+git${SRCPV}"
SRC_URI = "git://github.com/google/protobuf.git"
EXTRA_OECONF += " --with-protoc=echo"
inherit autotools
S = "${WORKDIR}/git"
FILES_${PN}-compiler = "${bindir} ${libdir}/libprotoc${SOLIBS}"
BBCLASSEXTEND = "native nativesdk"
Here is the more complete error statement:
| arm-agl-linux-gnueabi-libtool: link: arm-agl-linux-gnueabi-g++ -march=armv7-a -marm -mfpu=neon -mfloat-abi=softfp -mcpu=cortex-a9 --sysroot=/home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4 -fPIC -DPIC -shared -nostdlib /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/Scrt1.o /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/crti.o /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/arm-agl-linux-gnueabi/6.2.0/crtbeginS.o google/protobuf/stubs/.libs/atomicops_internals_x86_gcc.o google/protobuf/stubs/.libs/atomicops_internals_x86_msvc.o google/protobuf/stubs/.libs/common.o google/protobuf/stubs/.libs/once.o google/protobuf/stubs/.libs/stringprintf.o google/protobuf/.libs/extension_set.o google/protobuf/.libs/generated_message_util.o google/protobuf/.libs/message_lite.o google/protobuf/.libs/repeated_field.o google/protobuf/.libs/wire_format_lite.o google/protobuf/io/.libs/coded_stream.o google/protobuf/io/.libs/zero_copy_stream.o google/protobuf/io/.libs/zero_copy_stream_impl_lite.o google/protobuf/stubs/.libs/strutil.o google/protobuf/stubs/.libs/substitute.o google/protobuf/stubs/.libs/structurally_valid.o google/protobuf/.libs/descriptor.o google/protobuf/.libs/descriptor.pb.o google/protobuf/.libs/descriptor_database.o google/protobuf/.libs/dynamic_message.o google/protobuf/.libs/extension_set_heavy.o google/protobuf/.libs/generated_message_reflection.o google/protobuf/.libs/message.o google/protobuf/.libs/reflection_ops.o google/protobuf/.libs/service.o google/protobuf/.libs/text_format.o google/protobuf/.libs/unknown_field_set.o google/protobuf/.libs/wire_format.o google/protobuf/io/.libs/gzip_stream.o google/protobuf/io/.libs/printer.o google/protobuf/io/.libs/strtod.o google/protobuf/io/.libs/tokenizer.o google/protobuf/io/.libs/zero_copy_stream_impl.o google/protobuf/compiler/.libs/importer.o google/protobuf/compiler/.libs/parser.o -lpthread -lz -L/home/cjholmes/gen4/build/tmp/sysroots/x86_64-linux/usr/lib/arm-agl-linux-gnueabi/gcc/arm-agl-linux-gnueabi/6.2.0 -L/home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/lib -L/home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/arm-agl-linux-gnueabi/6.2.0 -L/home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/libstdc++.so -lm /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/libssp_nonshared.a -lc -lgcc_s -lgcc /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/arm-agl-linux-gnueabi/6.2.0/crtendS.o /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/crtn.o -march=armv7-a -marm -mfpu=neon -mfloat-abi=softfp -mcpu=cortex-a9 --sysroot=/home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4 -pthread -O2 -g -fstack-protector-strong -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -fstack-protector-strong -Wl,-z -Wl,relro -Wl,-z -Wl,now -pthread -Wl,-soname -Wl,libprotobuf.so.9 -o .libs/libprotobuf.so.9.0.1
| arm-agl-linux-gnueabi-libtool: link: arm-agl-linux-gnueabi-g++ -march=armv7-a -marm -mfpu=neon -mfloat-abi=softfp -mcpu=cortex-a9 --sysroot=/home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4 -fPIC -DPIC -shared -nostdlib /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/Scrt1.o /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/crti.o /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/arm-agl-linux-gnueabi/6.2.0/crtbeginS.o google/protobuf/stubs/.libs/atomicops_internals_x86_gcc.o google/protobuf/stubs/.libs/atomicops_internals_x86_msvc.o google/protobuf/stubs/.libs/common.o google/protobuf/stubs/.libs/once.o google/protobuf/stubs/.libs/stringprintf.o google/protobuf/.libs/extension_set.o google/protobuf/.libs/generated_message_util.o google/protobuf/.libs/message_lite.o google/protobuf/.libs/repeated_field.o google/protobuf/.libs/wire_format_lite.o google/protobuf/io/.libs/coded_stream.o google/protobuf/io/.libs/zero_copy_stream.o google/protobuf/io/.libs/zero_copy_stream_impl_lite.o -lpthread -lz -L/home/cjholmes/gen4/build/tmp/sysroots/x86_64-linux/usr/lib/arm-agl-linux-gnueabi/gcc/arm-agl-linux-gnueabi/6.2.0 -L/home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/lib -L/home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/arm-agl-linux-gnueabi/6.2.0 -L/home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/libstdc++.so -lm /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/libssp_nonshared.a -lc -lgcc_s -lgcc /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/arm-agl-linux-gnueabi/6.2.0/crtendS.o /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/crtn.o -march=armv7-a -marm -mfpu=neon -mfloat-abi=softfp -mcpu=cortex-a9 --sysroot=/home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4 -pthread -O2 -g -fstack-protector-strong -Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed -fstack-protector-strong -Wl,-z -Wl,relro -Wl,-z -Wl,now -pthread -Wl,-soname -Wl,libprotobuf-lite.so.9 -o .libs/libprotobuf-lite.so.9.0.1
| ERROR: oe_runmake failed
| /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
| /usr/src/debug/glibc/2.24-r0/git/csu/elf-init.c:87: undefined reference to `__init_array_end'
| /usr/src/debug/glibc/2.24-r0/git/csu/elf-init.c:87: undefined reference to `__init_array_start'
| /home/cjholmes/gen4/build/tmp/sysroots/x86_64-linux/usr/libexec/arm-agl-linux-gnueabi/gcc/arm-agl-linux-gnueabi/6.2.0/ld: .libs/libprotobuf-lite.so.9.0.1: hidden symbol `__init_array_end' isn't defined
| /home/cjholmes/gen4/build/tmp/sysroots/x86_64-linux/usr/libexec/arm-agl-linux-gnueabi/gcc/arm-agl-linux-gnueabi/6.2.0/ld: final link failed: Bad value
| collect2: error: ld returned 1 exit status
| make[3]: *** [libprotobuf-lite.la] Error 1
| make[3]: *** Waiting for unfinished jobs....
| /home/cjholmes/gen4/build/tmp/sysroots/imx6dlleargen4/usr/lib/libc_nonshared.a(elf-init.oS): In function `__libc_csu_init':
| /usr/src/debug/glibc/2.24-r0/git/csu/elf-init.c:87: undefined reference to `__init_array_end'
| /usr/src/debug/glibc/2.24-r0/git/csu/elf-init.c:87: undefined reference to `__init_array_start'
| /home/cjholmes/gen4/build/tmp/sysroots/x86_64-linux/usr/libexec/arm-agl-linux-gnueabi/gcc/arm-agl-linux-gnueabi/6.2.0/ld: .libs/libprotobuf.so.9.0.1: hidden symbol `__init_array_end' isn't defined
| /home/cjholmes/gen4/build/tmp/sysroots/x86_64-linux/usr/libexec/arm-agl-linux-gnueabi/gcc/arm-agl-linux-gnueabi/6.2.0/ld: final link failed: Bad value
| collect2: error: ld returned 1 exit status
| make[3]: *** [libprotobuf.la] Error 1
| make[3]: Leaving directory `/home/cjholmes/gen4/build/tmp/work/cortexa9-neon-agl-linux-gnueabi/protobuf/2.6.1+gitAUTOINC+bba83652e1-r0/build/src'
| make[2]: *** [all] Error 2
| make[2]: Leaving directory `/home/cjholmes/gen4/build/tmp/work/cortexa9-neon-agl-linux-gnueabi/protobuf/2.6.1+gitAUTOINC+bba83652e1-r0/build/src'
| make[1]: *** [all-recursive] Error 1
| make[1]: Leaving directory `/home/cjholmes/gen4/build/tmp/work/cortexa9-neon-agl-linux-gnueabi/protobuf/2.6.1+gitAUTOINC+bba83652e1-r0/build'
| make: *** [all] Error 2
| WARNING: /home/cjholmes/gen4/build/tmp/work/cortexa9-neon-agl-linux-gnueabi/protobuf/2.6.1+gitAUTOINC+bba83652e1-r0/temp/run.do_compile.121250:1 exit 1 from 'exit 1'
| ERROR: Function failed: do_compile (log file is located at /home/cjholmes/gen4/build/tmp/work/cortexa9-neon-agl-linux-gnueabi/protobuf/2.6.1+gitAUTOINC+bba83652e1-r0/temp/log.do_compile.121250)
I could really use some pointers on what to look at next. This has eaten a lot of hours already.
When compiling ltrace with icecc we run into a compilation problem. This is the minimal example:
main.c
#include <assert.h>
int main(int argc, char **argv) {
assert(argc != argc);
return 0;
}
test.sh:
#!/bin/bash
set -x
# one step compilation (no warning)
gcc -Wall main.c
# splitted compilation (warning)
gcc -Wall -E main.c -o main.i
gcc -Wall --preprocessed main.i
output:
++ gcc -Wall main.c
++ gcc -Wall -E main.c -o main.i
++ gcc -Wall --preprocessed main.i
main.c: In function ‘main’:
main.c:4:10: warning: self-comparison always evaluates to false [-Wtautological-compare]
assert(argc != argc);
^~
As you can see the result is different when compiling in one step and when preprocessing and compiling in two steps. Is this intended behavior?
I use gcc 6.3, the issue also appears in gcc 6.2 for ARM. I also cannot ignore this, as the full example uses -Werror.
The environments are Cent OS 6.7, boost-1.6.2, gcc-6.2.0
I have tried to install a software, but I got some errors.
Are theses errors come from g++ ? or boost?
I can't understand these messages.. because I have never been use g++..
Here is starting line.
[root#cms CASMcode-0.2.0]# scons install
scons: Reading SConscript files ...
rm /usr/local/include/casm
scons: done reading SConscript files.
scons: Building targets ...
Install directory: "include/casm" as "/usr/local/include/casm"
/usr/local/gcc-6.2/bin/g++-6.2 -o src/casm/version/version.os -c -DNDEBUG -O3 --std=c++11 -Wno-deprecated-register -Wno-deprecated-declarations -DEIGEN_DEFAULT_DENSE_INDEX_TYPE=long -Wno-unused-parameter -DNDEBUG -O3 -DGZSTREAM_NAMESPACE=gz -fPIC -Iinclude src/casm/version/version.cc
/usr/local/gcc-6.2/bin/g++-6.2 -o src/casm/clex/ConfigIOStrucScore.os -c -DNDEBUG -O3 --std=c++11 -Wno-deprecated-register -Wno-deprecated-declarations -DEIGEN_DEFAULT_DENSE_INDEX_TYPE=long -Wno-unused-parameter -DNDEBUG -O3 -DGZSTREAM_NAMESPACE=gz -fPIC -Iinclude -I/usr/local/boost_1_62_0/include src/casm/clex/ConfigIOStrucScore.cc
In file included from include/casm/external/Eigen/Core:263:0,
from include/casm/external/Eigen/Dense:1,
from include/casm/CASM_global_definitions.hh:13,
from include/casm/casm_io/EigenDataStream.hh:3,
from src/casm/clex/ConfigIOStrucScore.cc:3:
Error message appear here.
In file included from include/casm/casm_io/DataFormatterTools.hh:1291:0,
from include/casm/casm_io/DataFormatter_impl.hh:3,
from include/casm/casm_io/DataFormatter.hh:757,
from include/casm/clex/ConfigIO.hh:4,
from src/casm/clex/ConfigIOStrucScore.cc:6:
include/casm/casm_io/DataFormatterTools_impl.hh: In member function 'bool CASM::DataFormatterOperator<ValueType, ArgType, DataObject>::parse_args(const string&)':
include/casm/casm_io/DataFormatterTools_impl.hh:33:33: error: invalid initialization of reference of type 'const wstring& {aka const std::__cxx11::basic_string<wchar_t>&}' from expression of type 'std::__cxx11::string {aka std::__cxx11::basic_string<char>}'
val = std::stod(ttag);
^
And here
In file included from include/casm/clex/PrimClex.hh:14:0,
from include/casm/clex/ConfigIOStrucScore.hh:6,
from src/casm/clex/ConfigIOStrucScore.cc:7:
include/casm/clex/ChemicalReference.hh: In member function 'void CASM::ChemicalReferencePrinter::print(const std::vector<CASM::ChemicalReferenceState>&)':
include/casm/clex/ChemicalReference.hh:366:27: error: 'round' is not a member of 'std'
if(almost_equal(std::round(num), num, 1e-14)) {
^~~
I'm trying to setup Mingw-w64 as the mex compiler in MATLAB 2013a. My laptop has x86_64 architecture and runs windows 7. The program I want to compile uses c++11-style threading, so I'm using mingw-w64 version 4.9.0 with posix threads.
According to instruction I found here and here, I modified my mexopts.bat file. The code seems to compile successfully, but the linker reports an error. Does anyone have suggestions what I might be doing wrong?
By the way, I tried using gnumex to setup the compiler, but that didn't work either.
Here's the output and error message that MATLAB gives:
>mex -v Gomoku_mex.cpp
-> Default options filename found in C:\Users\Bas\AppData\Roaming\MathWorks\MATLAB\R2013a
-> Options file = C:\Users\Bas\AppData\Roaming\MathWorks\MATLAB\R2013a\mexopts.bat
MATLAB = C:\Program Files\MATLAB\R2013a
-> COMPILER = x86_64-w64-mingw32-g++
-> Compiler flags:
COMPFLAGS = -std=c++11 -fexceptions -I"C:\Program Files\MATLAB\R2013a\extern\include"
OPTIMFLAGS = -O3 -fexpensive-optimizations -DNDEBUG
DEBUGFLAGS = -g -Wall -Wextra
arguments =
Name switch = -o
-> Pre-linking commands=
-> LINKER = x86_64-w64-mingw32-g++
-> Link directives:
LINKFLAGS = -shared mex.def -L"C:\Program Files\MATLAB\R2013a\bin\win64" -static-libstdc++
LINKDEBUGFLAGS = -g -Wall
LINKFLAGSPOST = -lmex -lmx -lmat -lmwlapack -lmwblas
Name directive = -o "Gomoku_mex.mexw64"
File link directive =
Lib. link directive =
Rsp file indicator =
-> Resource Compiler =
-> Resource Linker =
----------------------------------------------------------------
--> x86_64-w64-mingw32-g++ -std=c++11 -fexceptions -I"C:\Program Files\MATLAB\R2013a\extern\include" -oC:\Users\Bas\AppData\Local\Temp\mex_r7jRw0\Gomoku_mex.obj -I"C:\Program Files\MATLAB\R2013a\extern\include" -I"C:\Program Files\MATLAB\R2013a\simulink\include" -O3 -fexpensive-optimizations -DNDEBUG -DMX_COMPAT_32 Gomoku_mex.cpp
C:\Users\Bas\AppData\Local\Temp\cc4hwD3A.o:Gomoku_mex.cpp:(.text+0x9d1c): undefined reference to `mxGetPr'
C:\Users\Bas\AppData\Local\Temp\cc4hwD3A.o:Gomoku_mex.cpp:(.text+0x9d83): undefined reference to `mxCreateDoubleScalar'
C:/PROGRA~1/mingw-w64/x86_64-4.9.0-posix-seh-rt_v3-rev2/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.9.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\Bas\AppData\Local\Temp\cc4hwD3A.o: bad reloc address 0x0 in section `.pdata$_ZNKSt5ctypeIcE8do_widenEc'
collect2.exe: error: ld returned 1 exit status
C:\PROGRA~1\MATLAB\R2013A\BIN\MEX.PL: Error: Compile of 'Gomoku_mex.cpp' failed.
Error using mex (line 206)
Unable to complete successfully.
Edit: As extra information, this is my mexopts.bat file. I got this directly from one of the two links above and modified directory & compiler names and added -std=c++11
set MATLAB=%MATLAB%
set PATH=%PATH%;C:\PROGRA~1\mingw-w64\x86_64-4.9.0-posix-seh-rt_v3-rev2\mingw64\bin
set MW_TARGET_ARCH=win64
rem ********************************************************************
rem Compiler parameters
rem ********************************************************************
set COMPILER=x86_64-w64-mingw32-g++
set COMPFLAGS=-std=c++11 -fexceptions -I"%MATLAB%\extern\include"
set OPTIMFLAGS=-O3 -fexpensive-optimizations -DNDEBUG
set DEBUGFLAGS=-g -Wall -Wextra
set NAME_OBJECT=-o
rem ********************************************************************
rem Linker parameters
rem ********************************************************************
set PRELINK_CMDS1=echo EXPORTS > mex.def & echo mexFunction >> mex.def
set LINKER=x86_64-w64-mingw32-g++
set LINKFLAGS= -static-libstdc++ -shared mex.def -L"%MATLAB%\bin\win64" -L"%MATLAB%\extern\lib\win64\microsoft"
set LINKFLAGSPOST= -lmex -lmx -lmat -lmwlapack -lmwblas
set LINKOPTIMFLAGS=-O3
set LINKDEBUGFLAGS= -g -Wall
set LINK_FILE=
set LINK_LIB=
set NAME_OUTPUT=-o "%OUTDIR%%MEX_NAME%%MEX_EXT%"
set RSP_FILE_INDICATOR=
set POSTLINK_CMDS1=del mex.def
Take the following configuration file that I'm using (you'll need to adjust the path pointing to MinGW-w64 location accordingly):
mingw_mexopts.bat
#echo off
set MATLAB=%MATLAB%
set MW_TARGET_ARCH=win64
set PATH=C:\MinGW-w64\mingw64\bin;%PATH%
set COMPILER=x86_64-w64-mingw32-g++
set COMPFLAGS=-c -m64 -mwin32 -mdll -Wall -std=c++11 -DMATLAB_MEX_FILE
set OPTIMFLAGS=-DNDEBUG -O2
set DEBUGFLAGS=-g
set NAME_OBJECT=-o
set LINKER=x86_64-w64-mingw32-g++
set LINKFLAGS=-shared -L"%MATLAB%\extern\lib\win64\microsoft" -L"%MATLAB%\bin\win64"
set LINKFLAGSPOST=-lmx -lmex -lmat
set LINKOPTIMFLAGS=-O2
set LINKDEBUGFLAGS=-g
set LINK_FILE=
set LINK_LIB=
set NAME_OUTPUT=-o "%OUTDIR%%MEX_NAME%%MEX_EXT%"
Next here is a simple MEX-function that uses C++11 threads:
test.cpp
#include "mex.h"
#include <vector>
#include <thread>
void say_hello(int tid) {
mexPrintf("hello from %d\n", tid);
}
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
std::vector<std::thread> threads;
for (int i=0; i<10; i++) {
threads.push_back(std::thread(say_hello, i));
}
for(auto& t : threads) {
t.join();
}
}
Finally we compile and run it in MATLAB:
>> mex -f mingw_mexopts.bat -largeArrayDims test.cpp
>> setenv('PATH', ['C:\MinGW-w64\mingw64\bin;', getenv('PATH')])
>> test
hello from 0
hello from 4
hello from 2
hello from 3
hello from 5
hello from 1
hello from 6
hello from 8
hello from 7
hello from 9
Note that if you're going to deploy this to another machine, you'll have to also copy a few dependent DLL's (you'll find them in MinGW bin folder), and place them next to the MEX-file. Use Dependency Walker to list them. In my case it was:
libstdc++-6.dll
libgcc_s_seh-1.dll
libwinpthread-1.dll
I am using GCC 4.8.2 with MATLAB R2014a running on 64-bit Windows.
Note these error messages:
C:\Users\Bas\AppData\Local\Temp\cc4hwD3A.o:Gomoku_mex.cpp:(.text+0x9d1c): undefined reference to `mxGetPr'
C:\Users\Bas\AppData\Local\Temp\cc4hwD3A.o:Gomoku_mex.cpp:(.text+0x9d83): undefined reference to `mxCreateDoubleScalar'
The library search path for libmex, libmx, libmat, ... is not added in your link command. The directory in your script is the bin directory containing DLLs. That's not correct here.
LINKFLAGS = -shared mex.def -L"C:\Program Files\MATLAB\R2013a\extern\lib\win64\microsoft" -static-libstdc++
While trying to build the mysql2 gem with ruby 1.9.2-p320 on Fedora 16, I ran into this error,
reproducible like so:
gremlin:mysql2 $ cat conftest.c
#include "ruby.h"
/*top*/
int main() {return 0;}
int t() {
void ((*volatile p)());
p = (void ((*)()))rb_thread_blocking_region;
return 0;
}
gremlin:mysql2 $ gcc -o conftest -I/usr/local/include/ruby-1.9.1/i686-linux \
-I/usr/local/include/ruby-1.9.1/ruby/backward
-I/usr/local/include/ruby-1.9.1 -I.
-I/usr/local/include/ruby-1.9.1/
-D_FILE_OFFSET_BITS=64 -O3 -ggdb -Wextra -Wno-unused-parameter
-Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers
-Wno-long-long conftest.c -L. -L/usr/local/lib -Wl,-R/usr/local/lib -L.
-rdynamic -Wl,-export-dynamic -Wl,-R -Wl,/usr/local/lib -L/usr/local/lib
-lruby-static -lpthread -lrt -ldl -lnss3 -lcrypt -lm -lc
/usr/lib/gcc/i686-redhat-linux/4.6.3/../../../libcrypt.a(md5-crypt.o):
In function `__md5_crypt_r':
(.text+0x96): undefined reference to `NSSLOW_Init'
/usr/lib/gcc/i686-redhat-linux/4.6.3/../../../libcrypt.a(md5-crypt.o):
In function `__md5_crypt_r':
(.text+0xb1): undefined reference to `NSSLOWHASH_NewContext'
... and many more messages for other global functions in the nsslowhash library,
which it looks like /usr/lib/libcrypt.a expects to have available, but I don't have
it installed, and can't find the source for.
Actually, that's not totally true. I found nsslowhash as part of
the Mozilla-Central build for Firefox, but when I run nm on the compiled
.a and .so files, none of them define anything that matches NSSLOW.
So where do these names come from?
Any help appreciated.
Problem solved by adding -lfreebl3 to the LIBS CONFIG setting.