Undefined reference to function error - c++

I have received a .h file to be used as part of a c++ program. I tried every method to link it, yet the undefined reference error is occurring. I'm using NetBeans in ubuntu.
The .h file contains the functions I'm trying to use. And yet the compiler is unable to find the function.
Here's a snippet of the fwlib32.h file since it is too big to insert the whole file:
FWLIBAPI short WINAPI cnc_allclibhndl3( const char *, unsigned short, long, unsigned short * );
FWLIBAPI short WINAPI cnc_upstart3( unsigned short, short, long, long ) ;
FWLIBAPI short WINAPI cnc_upstart3_f( unsigned short, short, char *, char * ) ;
FWLIBAPI short WINAPI cnc_statinfo( unsigned short, ODBST * ) ;
FWLIBAPI short WINAPI cnc_upload3( unsigned short, long *, char * ) ;
FWLIBAPI short WINAPI cnc_upend3( unsigned short ) ;
FWLIBAPI short WINAPI cnc_freelibhndl( unsigned short ) ;
Here's my program file:
#include "fwlib32.h"
#include<pthread.h>
#include<stdio.h>
#include<string.h>
#define BUFSIZE 1280
static unsigned short H;
struct conn_data
{
char ip[100];
short prt;
long tmo;
long pnum;
};
void conn(char *ipadd, short port, long tmout )
{
unsigned short h;
short ret;
ODBST buf;
ret = cnc_allclibhndl3( ipadd, port, tmout, &h ) ;
if ( !ret ) {
cnc_statinfo( h, &buf ) ;
H=h;
}
else
printf( "ERROR!(%d)\n", ret ) ;
}
short upld( long prgnum )
{
unsigned short h=H;
char buf[BUFSIZE+1] ;
short ret ;
long len;
ret = cnc_upstart3( h, 0, prgnum, prgnum ) ;
if ( ret ) return ( ret ) ;
do {
len = BUFSIZE ;
ret = cnc_upload3( h, &len, buf ) ;
if ( ret == EW_BUFFER ) {
continue ;
}
if ( ret == EW_OK ) {
buf[len] = '\0' ;
printf( "%s", buf ) ;
}
if ( buf[len-1] == '%' ) {
break ;
}
} while ( ret == EW_OK ) ;
ret = cnc_upend3( h ) ;
return ( ret ) ;
pthread_exit(&ret);
}
void* start_thread(void * dat)
{
struct conn_data *data;
data = (struct conn_data *)dat;
conn(data->ip, data->prt, data->tmo);
upld(data->pnum);
}
int main()
{
struct conn_data data;
char ip[100];
short prt;
long tmo,pnum;
pthread_t thread1;
int *ptr;
printf("\nEnter the IP address\n");
scanf("%s",ip);
strcpy(data.ip,ip);
printf("\nEnter the port number\n");
scanf("%hd",&prt);
data.prt=prt;
printf("\nEnter the timeout period in seconds\n");
scanf("%ld",&tmo);
data.tmo=tmo;
printf("Enter the program number\n");
scanf("%ld",&pnum);
data.pnum=pnum;
pthread_create(&thread1, NULL, start_thread, (void*)&data);
pthread_join(thread1, (void **) &ptr);
cnc_freelibhndl( H ) ;
return 0;
}
and these are the contents of the compiler window in NetBeans:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .clean-conf
make[1]: Entering directory `/home/niketh/NetBeansProjects/AmiT1'
rm -f -r build/Debug
rm -f dist/Debug/GNU-Linux-x86/amit1
make[1]: Leaving directory `/home/niketh/NetBeansProjects/AmiT1'
CLEAN SUCCESSFUL (total time: 56ms)
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `/home/niketh/NetBeansProjects/AmiT1'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/amit1
make[2]: Entering directory `/home/niketh/NetBeansProjects/AmiT1'
mkdir -p build/Debug/GNU-Linux-x86
rm -f build/Debug/GNU-Linux-x86/connect.o.d
g++ -c -g -MMD -MP -MF build/Debug/GNU-Linux-x86/connect.o.d -o build/Debug/GNU-Linux-x86/connect.o connect.cpp
mkdir -p dist/Debug/GNU-Linux-x86
g++ -o dist/Debug/GNU-Linux-x86/amit1 build/Debug/GNU-Linux-x86/connect.o -lpthread
build/Debug/GNU-Linux-x86/connect.o: In function `conn(char*, short, long)':
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:22: undefined reference to `cnc_allclibhndl3'
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:24: undefined reference to `cnc_statinfo'
build/Debug/GNU-Linux-x86/connect.o: In function `upld(long)':
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:37: undefined reference to `cnc_upstart3'
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:41: undefined reference to `cnc_upload3'
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:53: undefined reference to `cnc_upend3'
build/Debug/GNU-Linux-x86/connect.o: In function `main':
/home/niketh/NetBeansProjects/AmiT1/connect.cpp:88: undefined reference to `cnc_freelibhndl'
collect2: error: ld returned 1 exit status
make[2]: *** [dist/Debug/GNU-Linux-x86/amit1] Error 1
make[2]: Leaving directory `/home/niketh/NetBeansProjects/AmiT1'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `/home/niketh/NetBeansProjects/AmiT1'
make: *** [.build-impl] Error 2
BUILD FAILED (exit value 2, total time: 220ms)
I looked at other similar questions and tried to add the library file in the project properties option, or to just create a -lfwlib32 option in the g++ statement. None of them caused any change. The program would still not build. Can anyone please help me?

turns out the libfwlib32.so file is for 32 bit systems, while mine is a 64 bit system. i'll try to run it in the 32 bit system compatibilty

Related

Error when compiling MATIO library: "Undefined reference to 'Mat_Open'"

so after building and installing the MATIO library using CMake, I am now having problems compiling it. Here's my code:
#include <iostream>
#include <matio.h>
#define tS(x) std::cout<<"\t"<<(#x)<<" == "<<(x)<<"\n"
int main(int argc, char **argv)
{
const char *fileName = argc==1?"./S.mat":argv[1] ;
mat_t *mat = Mat_Open(fileName,MAT_ACC_RDONLY);
if(mat)
{
std::cout<<"A file was opened for reading\n\tmat == "<<mat<<"\n" ;
matvar_t *matVar=0 ;
std::cout<<"Writing out the data\n\n" ;
std::cout<<"x:\n" ;
matVar = Mat_VarRead(mat, (char*)"x") ;
if(matVar)
{
int xSize = matVar->nbytes/matVar->data_size ;
const double *xData = static_cast<const double*>(matVar->data) ;
for(int i=0; i<xSize; ++i)
{
std::cout<<"\tx["<<i<<"] = "<<xData[i]<<"\n" ;
}
std::cout<<"\n" ;
for(int i=0; i<matVar->rank; ++i)
{
std::cout<<"\tdim["<<i<<"] == "<<matVar->dims[i]<<"\n" ;
}
}
std::cout<<"y:\n" ;
matVar = Mat_VarRead(mat, (char*)"y") ;
int ySize = matVar->nbytes/matVar->data_size ;
const double *yData = static_cast<const double*>(matVar->data) ;
for(int i=0; i<ySize; ++i)
{
double d = yData[i] ;
std::cout<<"\ty["<<i<<"] = "<<d<<"\n" ;
}
std::cout<<"\n" ;
for(int i=0; i<matVar->rank; ++i)
{
std::cout<<"\tdim["<<i<<"] == "<<matVar->dims[i]<<"\n" ;
}
Mat_Close(mat);
}
else
{
std::cout<<"File cannot be opened\n" ;
return 1;
}
return 0;
}
However I get the following error:
C:\WINDOWS\system32\cmd.exe /C ""C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/mingw32-make.exe" -j4 SHELL=cmd.exe -e -f Makefile"
"----------Building project:[ Test - Debug ]----------"
mingw32-make.exe[1]: Entering directory 'C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test'
"C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe" -c "C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp" -std=c++14 -Wall -g -O0 -Wall -I/Users/RS3/matio/getopt -I/matio/include -L/matio/bin -lmatio -o ./Debug/main.cpp.o -I. -I. -I"C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\eigen-3.3.9" -I"C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\Halton" -I"C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\quasimvnrnd"
"C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/g++.exe" -o ./Debug/Test #"Test.txt" -L. -L"C:\Users\RS3\Desktop\SCC HiWi\Code\C++\myGmm\UQ\eigen-3.3.9" -static-libgcc -static-libstdc++
./Debug/main.cpp.o: In function `main':
C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:38: undefined reference to `Mat_Open'
C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:46: undefined reference to `Mat_VarRead'
C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:63: undefined reference to `Mat_VarRead'
C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test/main.cpp:77: undefined reference to `Mat_Close'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[1]: *** [Test.mk:81: Debug/Test] Error 1
mingw32-make.exe[1]: Leaving directory 'C:/Users/RS3/Desktop/SCC HiWi/Code/C++/myGmm/UQ/Test'
mingw32-make.exe: *** [Makefile:5: All] Error 2
====4 errors, 0 warnings====
I looked for this error right and left and I know the linker can't find the library for some reason despite me having the following compiler options:
-g;-O0;-Wall;-I/Users/RS3/matio/getopt;-I/matio/include;-L/matio/bin;-lmatio
I'm using Codelite IDE.
I am not sure what I am missing and it's driving me crazy. Any help would be appreciated!

multiple definition c++/c google test

So ive looked at similar issues and I followed what they said. I have made sure that my .h and .cpp file are in my main test file.
So I'm not really sure whats wrong. I fixed an earlier error like this but it was something I caught. Id appreciate some help.
Matrix-Multiply.h
Matrix-Multiply.h
#ifndef __MATRIX_MULTIPLY_H
#define __MATRIX_MULTIPLY_H
#include<stdio.h>
#include<stdlib.h>
float *expectedFinalMatrixOutput(int mA,int nA,int mB,int nB,float *matA,float *matB);
int readFiles(const char *matAFile,const char *matBFile);
#endif //__MATRIX_MULTIPLY_H
Matrix-Multiply.cpp
//.cpp file
#include<stdio.h>
#include<stdlib.h>
float *expectedFinalMatrixOutput(int mA,int nA,int mB,int nB,float *matA,float *matB)
{
int m = mA;
int n = nB;
int size = m * n;
float *finalMatrix[size];
//build both matrices
//for both the matA Column and matB Row need to be the
//same before even multiplying
//dot product matrix
//the end matrix needs the have the same number of rows as
//matA and same number of columns as matB
return *finalMatrix;
}
int readFiles(const char *matAFile,const char *matBFile)
{
int flag;
//read in file for matrixs
//set flag for whether true or false
//verify row and column being taken have actual values and
//that the sized are correct
return flag;
}
Matrix-Multiply_unittests.cpp
// tests.cpp
#include "Matrix-Multiply.h"
#include "Matrix-Multiply.cpp"
#include<gtest/gtest.h>
#include<stdio.h>
TEST(matrixSize,emptyMatrix)
{
float *matA = NULL;
float *matB = NULL;
float *matrix =
expectedFinalMatrixOutput(0,0,0,0,matA,matB);
ASSERT_EQ(*(matrix),0);
}
TEST(dotTest,oneByoneMatrix)
{
float fMatrix[1] = {1};
float sMatrix[1] = {1};
float *matrix = expectedFinalMatrixOutput(1,1,1,1,fMatrix,sMatrix);
ASSERT_EQ(matrix[0],1);
}
TEST(dotTest,twoBytwoMatrix)
{
float fMatrix[4] = {1,1,1,1};
float sMatrix[4] = {1,1,1,1};
float *matrix = expectedFinalMatrixOutput(2,2,2,2,fMatrix,sMatrix);
for(int i =0;i<4;i++)
{
EXPECT_EQ(2,matrix[i]);
}
}
TEST(ReadFilesTest,filesExist)
{
const char *matA = "../src/Matrix1_3_3.txt";
const char *matB = "../src/Matrix2_3_3.txt";
ASSERT_EQ(0,readFiles(matA,matB));
}
TEST(ReadFilesTest,filesDontExist)
{
const char *matA = "../src/notReal.txt";
const char *matB = "../src/Matrix2_3_3.txt";
ASSERT_EQ(0,readFiles(matA,matB));
}
TEST(ReadFilesTest,matrixSizeNotCompatible)
{
const char *matA = "../src/Matrix1_3_3.txt";
const char *matB = "../src/Matrix2_2_2.txt";
ASSERT_EQ(0,readFiles(matA,matB));
}
int main(int argc,char **argv)
{
testing::InitGoogleTest(&argc,argv);
return RUN_ALL_TESTS();
}
Sorry if its not all on one line. I tried to get it that way. But the error i get is:
obj/Matrix-Multiply.o: In function `expectedFinalMatrixOutput(int, int, int,
int, float*, float*)':
Matrix-Multiply.cpp:(.text+0x0): multiple definition of
`expectedFinalMatrixOutput(int, int, int, int, float*, float*)'
/tmp/ccUgZRUB.o:Matrix-Multiply_unittests.cpp:(.text+0x0): first defined
here
obj/Matrix-Multiply.o: In function `readFiles(char const*, char const*)':
Matrix-Multiply.cpp:(.text+0xbe): multiple definition of `readFiles(char
const*, char const*)'
/tmp/ccUgZRUB.o:Matrix-Multiply_unittests.cpp:(.text+0xbe): first defined
here
collect2: error: ld returned 1 exit status
make: *** [test] Error 1
Im using googletest and already make a call to make gtest
However this error occurs when i call make test.
Any help is appreciated
Makefile
CPP=g++
OBJ=obj
SRC=src
BIN=bin
CPPFLAGS=-I$(SRC)
GTEST_DIR=../googletest/googletest
gtest:
mkdir -p $(OBJ)
${CPP} -I${GTEST_DIR}/include -I${GTEST_DIR} \
-pthread -c ${GTEST_DIR}/src/gtest-all.cc -o $(OBJ)/gtest-all.o
ar -rv $(OBJ)/libgtest.a $(OBJ)/gtest-all.o
GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
$(OBJ)/gtest_main.o : $(GTEST_SRCS_)
$(CXX) $(CPPFLAGS) -I${GTEST_DIR}/include -I$(GTEST_DIR) $(CXXFLAGS) -c
\
$(GTEST_DIR)/src/gtest_main.cc -o $#
$(OBJ)/gtest_main.a : $(OBJ)/gtest-all.o $(OBJ)/gtest_main.o
$(AR) $(ARFLAGS) $# $^
$(OBJ)/%.o: $(SRC)/%.cpp
$(CPP) $(CPPFLAGS) $(CXXFLAGS) -c -o $# $<
.PHONY: test clean
test: $(OBJ)/Matrix-Multiply.o $(OBJ)/gtest_main.a
mkdir -p $(BIN)
$(CPP) -I${GTEST_DIR}/include $(SRC)/Matrix-Multiply_unittests.cpp \
$(OBJ)/gtest_main.a $(OBJ)/Matrix-Multiply.o -o $(BIN)/Matrix-
Multiply_unittests -pthread
$(BIN)/Matrix-Multiply_unittests
clean:
rm -f $(BIN)/*
rm -f $(OBJ)/*
I think by #include "Matrix-Multiply.cpp" you are including the functions once.
Also (although not shown), you are linking with Matrix-Multiply on the link line.
You should not normally include a .cpp file. They are better bound by linking the file.
g++ -o my_awesome_app main.o Matrix-Multiply.o otherfile.o

iconv() 32 bit vs 64 bit on Linux

I have a bit of code that uses iconv() on Linux to validate a string as being UTF-8 encoded. The conversion I create like:
iconv_t c = iconv_open("UTF-8","UTF-8");
I run iconv() like:
int status = iconv(c, &fromArray, (size_t*)&inSize, &toArray, (size_t*)&outSize);
I then take the string to have valid UTF-8 if status is not -1.
This compiles and works fine in a 32 bit environment (where it was initially developed and tested). However I now have a requirement to get this working in a 64 bit environment (to be specific the 64 bit flavor of Fedora 14 I believe). When I compile and run a test on this there status is always -1 and I always get an EILSEQ error in errno, even for the same string which the 32 bit compile says is fine.
Does anyone have any ideas as to why this might be happening?
Recently had experienced same issue. Casting to (size_t*) is more (very) likely the root cause.
The problem even could be easy simulated with next code:
cat >Makefile <<EOF
all: build test clean
clean:
rm -f *.o core* t32 t64
test: build
#echo ; echo "run_32bit version:" ; ./t32
#echo ; echo "run_64bit version:" ; ./t64
build:
g++ -m32 t.cpp -o t32 -Wall -O0 -g
g++ t.cpp -o t64 -Wall -O0 -g
EOF
cat >t.cpp <<EOF
#include <errno.h>
#include <stdio.h>
#include <iconv.h>
char buff_toArray [BUFSIZ];
char buff_fromArray [] = \
"<TESTS_STRINGS>\
<T_VERIFICATION_STRINGS/>\
</TESTS_STRINGS>";
void iconv_test ( const char* desc, size_t* size )
{
printf ("%s = size[%zu]\n",desc, (*size) );
}
int main (int argc, char* argv[])
{
char* toArray = &buff_toArray[0];
char* fromArray = &buff_fromArray[0];
const int inSize_const = 61;
short inSize_short = (short) sizeof(buff_fromArray);
int inSize_int = (int) sizeof(buff_fromArray);
unsigned int inSize_uint = (unsigned int) sizeof(buff_fromArray);
long inSize_long = (long) sizeof(buff_fromArray);
long long inSize_llong = (long long) sizeof(buff_fromArray);
size_t inSize_size_t = sizeof(buff_fromArray);
printf ("fake iconv usage:\n");
iconv_test((const char*) "inSize_const", (size_t*)&inSize_const);
iconv_test((const char*) "inSize_short", (size_t*)&inSize_short);
iconv_test((const char*) "inSize_int", (size_t*)&inSize_int);
iconv_test((const char*) "inSize_uint", (size_t*)&inSize_uint);
iconv_test((const char*) "inSize_long", (size_t*)&inSize_long);
iconv_test((const char*) "inSize_llong", (size_t*)&inSize_llong);
iconv_test((const char*) "inSize_size_t", &inSize_size_t);
printf ("real iconv usage:\n");
int inSize = sizeof(buff_fromArray);
int outSize = sizeof(buff_toArray);
iconv_t c = iconv_open("UTF-8","UTF-8");
int status = iconv(c, &fromArray, (size_t*)&inSize, &toArray, (size_t*)&outSize);
printf ("status=[%d], errno=[%d] \n", status, errno );
printf ("result string:\n");
for(size_t i = 0; i <= sizeof(buff_toArray); i++) { printf ("%c", buff_toArray[i]); }
printf ("\n");
int close_status = iconv_close(c);
printf ("close status=[%d], errno=[%d] \n", close_status, errno );
return 0;
}
EOF

Can't run make using C++ stdlib system call

I've got the following code in C++
if (should_run_make) {
std::string make = "make -C ";
make.append(outdir);
std::cout << "Make cmd is " << make << std::endl;
system(make.c_str());
}
This reports the following:
Make cmd is make -C /home/hamiltont/temp/ make: Entering directory
/home/hamiltont/temp' make: *** No targets. Stop.
make: Leaving directory/home/hamiltont/temp'
However, doing it manually works fine in multiple ways e.g.
[hamiltont#4 generator]$ make -C /home/hamiltont/temp/
make: Entering directory `/home/hamiltont/temp'
g++ -O3 -I/usr/include/openmpi-x86_64 -L/usr/local/lib -L/usr/lib64/openmpi/lib -lmpi -lmpi_cxx -lboost_serialization -lboost_mpi stg_impl.cpp -o impl
make: Leaving directory `/home/hamiltont/temp'
[hamiltont#4 generator]$ cd /home/hamiltont/temp/
[hamiltont#4 temp]$ make
g++ -O3 -I/usr/include/openmpi-x86_64 -L/usr/local/lib -L/usr/lib64/openmpi/lib -lmpi -lmpi_cxx -lboost_serialization -lboost_mpi stg_impl.cpp -o impl
Are you generating the makefile from within your C program? That's the only reason I could imagine would cause that specific error message.
make: *** No targets. Stop.
Reproducing the error
Here's how I could generate that message:
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp = fopen("Makefile", "w");
fputs("all:\n\techo Done.\n", fp);
system("make");
fclose(fp);
return 0;
}
This, predictably, prints:
make: *** No targets. Stop.
I say predictably because Makefile will be empty! This is because IO is buffered...
Fixed version
So, I close the file before calling system(), which flushes the buffer (fflush() would also do the trick):
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp = fopen("Makefile", "w");
fputs("all:\n\techo Done.\n", fp);
fclose(fp);
system("make");
return 0;
}
Output:
echo Done.
Done.
I used C's IO functions for clarity, but the same rules apply to <iostream>.

Programs configured to use dmalloc bail-out citing header file error

While trying to compile lynx, I used the 'with-dmalloc' configure option. But compilation aborted, producing this error:
/usr/include/dmalloc.h:460: error: expected identifier or '(' before '__extension__'
> /usr/include/dmalloc.h:484: error: expected identifier or '(' before '__extension__'
> make[1]: *** [HTParse.o] Error 1
> make[1]: Leaving directory `/tmp/lynx2-8-8/WWW/Library/Implementation'
> make: *** [all] Error 2
This is what the errant lines in dmalloc.h hold:
> Line 460: char *strdup(const char *string);
> Linu 484: char *strndup(const char *string, const DMALLOC_SIZE len);
The file can also be viewed at http://www.filewatcher.com/p/dmalloc-5.5.2.tbz.467309/include/dmalloc.h.html
Development on dmalloc has pretty much stopped, so not really expecting a fix from upstream. Any help?
I faced with the similar problem while installing dmalloc on Fedora 21 x86_64:
dmalloc-5.5.2]$ make
rm -f dmalloc.h dmalloc.h.t
cat ./dmalloc.h.1 dmalloc.h.2 ./dmalloc.h.3 > dmalloc.h.t
mv dmalloc.h.t dmalloc.h
rm -f arg_check.o
gcc -g -O2 -DHAVE_STDARG_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 - DHAVE_UNISTD_H=1 -DHAVE_SYS_MMAN_H=1 -DHAVE_SYS_TYPES_H=1 - DHAVE_W32API_WINBASE_H=0 -DHAVE_W32API_WINDEF_H=0 -DHAVE_SYS_CYGWIN_H=0 - DHAVE_SIGNAL_H=1 -I. -I. -c arg_check.c -o ./arg_check.o
In file included from /usr/include/string.h:634:0,
from arg_check.c:33:
dmalloc.h:484:7: error: expected identifier or ‘(’ before ‘__extension__’
char *strndup(const char *string, const DMALLOC_SIZE len);
^
Makefile:362: recipe for target 'arg_check.o' failed
make: *** [arg_check.o] Error 1
Solved it by altering dmalloc-5.5.2/dmalloc.h.3:
- 432 | extern
- 433 | char *strndup(const char *string, const DMALLOC_SIZE len);
+ 432 | #undef strndup
+ 433 | extern
+ 434 | char *strndup(const char *string, const DMALLOC_SIZE len);
The source of wisdom: https://dev.openwrt.org/browser/packages/devel/dmalloc/patches/400-undef-strndup.patch?rev=31253
I encountered something like this and found that this was caused by the dmalloc.h was included before e.g. <unistd.h> et. al so that the macro identifiers from dmalloc.h mangled the declarations for the real valloc/realloc/memdup etc.
Could this be what you are seeing?