* Linux C++ Help
@ 2002-12-06 1:51 Jayanta Narayan Choudhuri
2002-12-06 4:43 ` Andrea 'fwyzard' Bocci
2002-12-06 4:59 ` Momchil Velikov
0 siblings, 2 replies; 5+ messages in thread
From: Jayanta Narayan Choudhuri @ 2002-12-06 1:51 UTC (permalink / raw)
To: gcc-help
[-- Attachment #1.1: Type: text/plain, Size: 2406 bytes --]
I am seeking your help ONLY after exhausting myself!
If you can help me get "g++ -o x.exe gplus.cpp" to link & work then rest
will hopefully follow.
I assumed that it will be easy to port STL C++ programs from Win32 to
Linux.
However after spending 36 hours I am stuck only in the last stage -
linking.
1. gcc or g++ automatically sense the include directories to search and
libraries to link(perhaps) depending on extension *.cpp or *.c
2. If you write a pure K&R C program or a pure C++ program(not using old
C stuff) there is no problem.
3. The problem is with C++ programs that also call stdio & strings &
ctype stuff. Compilation goes through fine but linking(collect2) fails.
Also pure C++ STL programs call C malloc & free and even if I get rid of
all K&R C stuff the linking fails.
4. I read all the internet HOW TO files and FAQs etc. but am in square
one.
5. There must be something VERY silly I have missed.
I am attaching a few files that you can easily use to replicate my
problem.
1. gcc -o x.exe jnc.c # WORKS
2. gcc -o x.exe jnc.cpp # FAILS even though jnc.c
& jnc.cpp are identical
3. g++ -o x.exe jnc.cpp # also FAILS
4. g++ -o x.exe gplus.cpp # also fails though I used the
recommended headers of C++
5. g++ -x c -o x.exe jnc.cpp # WORKS
I edited out all the K&R C stuff like fprintf/sprintf/toupper etc. from
my main STL project. As usual compilation is perfect but collect2 still
fails and cannot link pthread_mutex_lock, pthread_mutex_unlock, malloc
and free. I wrote a few NON STL C++ programs, which if bereft of C
calls, work fine. STL must be calling the above traditional stuff to
allocate memory and be thread safe and possible that is why it fails.
jnc_linux.txt which has the main diagnostic output is also attached.
You can imagine my frustration. Everything compiling perfectly - this
itself took quite a bit of effort. Yet I am stuck because I do not know
how to link. If you can help me get "g++ -o x.exe gplus.cpp" to work
then the rest will hopefully follow.
Looking forward to good news ....
Regards & Best Wishes
-jnc
Jayanta Narayan Choudhuri
Flat 302, 395 Jodhpur Park
Kolkata 700 068
India
Tel: 91(33)2473-1891
<mailto:sss@cal.vsnl.net.in> mailto:sss@cal.vsnl.net.in
url: <http://www.geocities.com/ojnc> http://www.geocities.com/ojnc
[-- Attachment #1.2: Type: text/html, Size: 7422 bytes --]
[-- Attachment #2: gplus.cpp --]
[-- Type: text/plain, Size: 839 bytes --]
#include <cstdio>
#include <ctime>
extern "C" {
#include <sys/types.h>
#include <sys/timeb.h>
}
#include <cctype>
// ------------------------------- MAIN PROGRAM --------------------------------
int main(int argc, char *argv[])
{
int intIter;
struct timeb timebuffer;
char *timeline;
ftime( &timebuffer );
timeline = ctime( & ( timebuffer.time ) );
for(intIter=0;intIter<strlen(timeline);intIter++)
*(timeline+intIter)=toupper(*(timeline+intIter));
fprintf(stderr,"Start ACFEScnv: %.8s.%hu\n", timeline+11, timebuffer.millitm);
ftime( &timebuffer );
timeline = ctime( & ( timebuffer.time ) );
fprintf(stderr,"End ACFEScnv: %.8s.%hu\n", timeline+11, timebuffer.millitm);
return 0;
} // END OF MAIN PROGRAM
[-- Attachment #3: jnc.c --]
[-- Type: text/plain, Size: 791 bytes --]
#include <stdio.h>
#include <time.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <ctype.h>
// ------------------------------- MAIN PROGRAM --------------------------------
int main(int argc, char *argv[])
{
int intIter;
struct timeb timebuffer;
char *timeline;
ftime( &timebuffer );
timeline = ctime( & ( timebuffer.time ) );
for(intIter=0;intIter<strlen(timeline);intIter++)
*(timeline+intIter)=toupper(*(timeline+intIter));
fprintf(stderr,"Start ACFEScnv: %.8s.%hu\n", timeline+11, timebuffer.millitm);
ftime( &timebuffer );
timeline = ctime( & ( timebuffer.time ) );
fprintf(stderr,"End ACFEScnv: %.8s.%hu\n", timeline+11, timebuffer.millitm);
return 0;
} // END OF MAIN PROGRAM
[-- Attachment #4: jnc.cpp --]
[-- Type: text/plain, Size: 791 bytes --]
#include <stdio.h>
#include <time.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <ctype.h>
// ------------------------------- MAIN PROGRAM --------------------------------
int main(int argc, char *argv[])
{
int intIter;
struct timeb timebuffer;
char *timeline;
ftime( &timebuffer );
timeline = ctime( & ( timebuffer.time ) );
for(intIter=0;intIter<strlen(timeline);intIter++)
*(timeline+intIter)=toupper(*(timeline+intIter));
fprintf(stderr,"Start ACFEScnv: %.8s.%hu\n", timeline+11, timebuffer.millitm);
ftime( &timebuffer );
timeline = ctime( & ( timebuffer.time ) );
fprintf(stderr,"End ACFEScnv: %.8s.%hu\n", timeline+11, timebuffer.millitm);
return 0;
} // END OF MAIN PROGRAM
[-- Attachment #5: jnc_linux.txt --]
[-- Type: text/plain, Size: 7580 bytes --]
/**
jnc.c analysis WORKS
**/
[jnc@sss ACFEScnvSTL]$ gcc -o x.exe jnc.c -v
Reading specs from /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/sp
ecs
gcc driver version 2.96 20000731 (Red Hat Linux 7.1 2.96-98) executing gcc versi
on egcs-2.91.66
/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/cpp0 -lang-c -v -ipr
efix /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/ -D__GNUC__=2 -D
__GNUC_MINOR__=91 -D__GNUC_PATCHLEVEL__=66 -D__ELF__ -Dunix -Di386 -D__i386__ -D
linux -D__ELF__ -D__unix__ -D__i386__ -D__i386__ -D__linux__ -D__unix -D__i386 -
D__linux -Asystem(posix) -D__NO_INLINE__ -Asystem(unix) -Acpu(i386) -Amachine(i3
86) -Di386 -D__i386 -D__i386__ -D__tune_i386__ jnc.c /tmp/ccGpIwW7.i
GNU CPP version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386 Linux/ELF
)
#include "..." search starts here:
#include <...> search starts here:
/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/include
/usr/local/include
/usr/i386-glibc21-linux/include
/usr/lib/gcc-lib/i386-glibc21-linux/egcs-2.91.66/include
/usr/include
End of search list.
/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/cc1 /tmp/ccGpIwW7.i
-quiet -dumpbase jnc.c -version -o /tmp/ccoXQczb.s
GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386-glibc21-lin
ux) compiled by GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release).
as -V -Qy -o /tmp/cc0P7sjj.o /tmp/ccoXQczb.s
GNU assembler version 2.11.90.0.8 (i386-redhat-linux) using BFD version 2.11.90.
0.8
/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/collect2 -m elf_i386
-dynamic-linker /lib/ld-linux.so.2 -o x.exe /usr/i386-glibc21-linux/lib/gcc-lib
/i386-redhat-linux/2.96/../../../crt1.o /usr/i386-glibc21-linux/lib/gcc-lib/i386
-redhat-linux/2.96/../../../crti.o /usr/i386-glibc21-linux/lib/gcc-lib/i386-redh
at-linux/2.96/crtbegin.o -L/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux
/2.96 -L/usr/i386-glibc21-linux/lib/gcc-lib -L/usr/lib/gcc-lib/i386-redhat-linux
/2.96 -L/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/../../.. -L/u
sr/lib/gcc-lib/i386-redhat-linux/2.96/../../.. /tmp/cc0P7sjj.o -lgcc -lc -lgcc /
usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/crtend.o /usr/i386-gli
bc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/../../../crtn.o
------------------------------------------------------------------------------------------
/**
jnc.cpp analysis FAILS
**/
[jnc@sss ACFEScnvSTL]$ gcc -o x.exe jnc.cpp -v
Reading specs from /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/sp
ecs
gcc driver version 2.96 20000731 (Red Hat Linux 7.1 2.96-98) executing gcc versi
on egcs-2.91.66
/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/cpp0 -lang-c++ -D__G
NUG__=2 -D__EXCEPTIONS -v -iprefix /usr/i386-glibc21-linux/lib/gcc-lib/i386-redh
at-linux/2.96/ -D__GNUC__=2 -D__GNUC_MINOR__=91 -D__GNUC_PATCHLEVEL__=66 -D__ELF
__ -Dunix -Di386 -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__i386__ -
D__linux__ -D__unix -D__i386 -D__linux -Asystem(posix) -D__NO_INLINE__ -Asystem(
unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_i386__ jnc
.cpp /tmp/ccqrbfWR.ii
GNU CPP version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386 Linux/ELF
)
#include "..." search starts here:
#include <...> search starts here:
/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/include
/usr/include/g++-2
/usr/local/include
/usr/i386-glibc21-linux/include
/usr/lib/gcc-lib/i386-glibc21-linux/egcs-2.91.66/include
/usr/include
End of search list.
/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/cc1plus /tmp/ccqrbfW
R.ii -quiet -dumpbase jnc.cpp -version -o /tmp/ccuyof6C.s
GNU C++ version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386-glibc21-l
inux) compiled by GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
.
as -V -Qy -o /tmp/ccChCOew.o /tmp/ccuyof6C.s
GNU assembler version 2.11.90.0.8 (i386-redhat-linux) using BFD version 2.11.90.
0.8
/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/collect2 -m elf_i386
-dynamic-linker /lib/ld-linux.so.2 -o x.exe /usr/i386-glibc21-linux/lib/gcc-lib
/i386-redhat-linux/2.96/../../../crt1.o /usr/i386-glibc21-linux/lib/gcc-lib/i386
-redhat-linux/2.96/../../../crti.o /usr/i386-glibc21-linux/lib/gcc-lib/i386-redh
at-linux/2.96/crtbegin.o -L/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux
/2.96 -L/usr/i386-glibc21-linux/lib/gcc-lib -L/usr/lib/gcc-lib/i386-redhat-linux
/2.96 -L/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/../../.. -L/u
sr/lib/gcc-lib/i386-redhat-linux/2.96/../../.. /tmp/ccChCOew.o -lgcc -lc -lgcc /
usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/crtend.o /usr/i386-gli
bc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/../../../crtn.o
/tmp/ccChCOew.o: In function `main':
/tmp/ccChCOew.o(.text+0xb): undefined reference to `ftime(timeb *)'
/tmp/ccChCOew.o(.text+0x17): undefined reference to `ctime(long const *)'
/tmp/ccChCOew.o(.text+0x52): undefined reference to `toupper(int)'
/tmp/ccChCOew.o(.text+0x88): undefined reference to `fprintf(_IO_FILE *, char co
nst *,...)'
/tmp/ccChCOew.o(.text+0x94): undefined reference to `ftime(timeb *)'
/tmp/ccChCOew.o(.text+0xa0): undefined reference to `ctime(long const *)'
/tmp/ccChCOew.o(.text+0xc4): undefined reference to `fprintf(_IO_FILE *, char co
nst *,...)'
collect2: ld returned 1 exit status
[jnc@sss ACFEScnvSTL]$
------------------------------------------------------------------------------------------
g++ -x c -o x.exe jnc.cpp WORKS
------------------------------------------------------------------------------------------
/**
My Main STL project with all legacy K&R C call stripped
FAILS at link time
**/
[jnc@sss ACFEScnvSTL]$ sh ac.sh
/tmp/cc6vMBEr.o: In function `__malloc_alloc_template<0>::oom_malloc(unsigned in
t)':
/tmp/cc6vMBEr.o(.__malloc_alloc_template<0>::gnu.linkonce.t.oom_malloc(unsigned
int)+0x3b): undefined reference to `exit(int)'
/tmp/cc6vMBEr.o(.__malloc_alloc_template<0>::gnu.linkonce.t.oom_malloc(unsigned
int)+0x4c): undefined reference to `malloc(unsigned int)'
/tmp/cc6vMBEr.o: In function `__malloc_alloc_template<0>::allocate(unsigned int)
':
/tmp/cc6vMBEr.o(.__malloc_alloc_template<0>::gnu.linkonce.t.allocate(unsigned in
t)+0xc): undefined reference to `malloc(unsigned int)'
/tmp/cc6vMBEr.o: In function `__default_alloc_template<true, 0>::chunk_alloc(uns
igned int, int &)':
/tmp/cc6vMBEr.o(.__default_alloc_template<1, 0>::gnu.linkonce.t.chunk_alloc(unsi
gned int, int &)+0x163): undefined reference to `malloc(unsigned int)'
/tmp/cc6vMBEr.o: In function `__default_alloc_template<true, 0>::lock::lock(void
)':
/tmp/cc6vMBEr.o(.__default_alloc_template<1, 0>::lock::gnu.linkonce.t.(void)+0x9
): undefined reference to `pthread_mutex_lock(pthread_mutex_t *)'
/tmp/cc6vMBEr.o: In function `__default_alloc_template<true, 0>::lock::~lock(voi
d)':
/tmp/cc6vMBEr.o(.gnu.linkonce.t._._Q2t24__default_alloc_template2b1i0_4lock+0x11
): undefined reference to `pthread_mutex_unlock(pthread_mutex_t *)'
/tmp/cc6vMBEr.o: In function `__malloc_alloc_template<0>::deallocate(void *, uns
igned int)':
/tmp/cc6vMBEr.o(.__malloc_alloc_template<0>::gnu.linkonce.t.deallocate(void *, u
nsigned int)+0xd): undefined reference to `free(void *)'
collect2: ld returned 1 exit status
[jnc@sss ACFEScnvSTL]$
------------------------------------------------------------------------------------------
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Linux C++ Help
2002-12-06 1:51 Linux C++ Help Jayanta Narayan Choudhuri
@ 2002-12-06 4:43 ` Andrea 'fwyzard' Bocci
2002-12-06 4:59 ` Momchil Velikov
1 sibling, 0 replies; 5+ messages in thread
From: Andrea 'fwyzard' Bocci @ 2002-12-06 4:43 UTC (permalink / raw)
To: Jayanta Narayan Choudhuri; +Cc: gcc-help
At 15.21 06/12/2002 +0530, Jayanta Narayan Choudhuri wrote:
>I am seeking your help ONLY after exhausting myself!
>
>If you can help me get "g++ -o x.exe gplus.cpp" to link & work then rest
>will hopefully follow.
Ehm, I don't know what to say, actually.
The only problem I found with your gplus.cpp is a missing
#include <cstring>
(gcc complained about strlen being undefind).
After adding it right after
#include <ctime>
all went smoothly.
I tried under RedHat Linux (gcc 2.96 and 3.2) and Cygwin (gcc 2.95 and
3.2), without any problem at all:
[Linux] $ g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --host=i386-redhat-linux --with-system-zlib
--enable-__cxa_atexit
Thread model: posix
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
[Linux] $ g++ -o x.exe gplus.cpp
[Linux] $ ./x.exe
Start ACFEScnv: 13:43:05.278
End ACFEScnv: 13:43:05.278
[Linux] $ g++296 -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux7/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-110)
[Linux] $ g++296 -o x.exe gplus.cpp
[Linux] $ ./x.exe
Start ACFEScnv: 13:43:57.531
End ACFEScnv: 13:43:57.539
C:\Documents and Settings\fwyzard\Desktop\test>g++-2 -v
Reading specs from /cygdrive/c/Program
Files/cygwin/bin/../lib/gcc-lib/i686-pc-cygwin/2.95.3-10/specs
gcc version 2.95.3-10 (cygwin special)
C:\Documents and Settings\fwyzard\Desktop\test>g++-2 -o x.exe gplus.cpp
C:\Documents and Settings\fwyzard\Desktop\test>x
Start ACFEScnv: 13:41:45.526
End ACFEScnv: 13:41:45.526
C:\Documents and Settings\fwyzard\Desktop\test>g++ -v
Reading specs from /cygdrive/c/Program
Files/cygwin/bin/../lib/gcc-lib/i686-pc-cygwin/3.2/specs
Configured with: /netrel/src/gcc-3.2-3/configure
--enable-languages=c,c++,f77,java --enable-libgcj --enable-threads=posix
--with-system-zlib --enable-nls --without-included-gettext
--enable-interpreter --disable-sjlj-exceptions
--disable-version-specific-runtime-libs --enable-shared
--build=i686-pc-linux --host=i686-pc-cygwin --target=i686-pc-cygwin
--enable-haifa --prefix=/usr --exec-prefix=/usr--sysconfdir=/etc
--libdir=/usr/lib --includedir=/nonexistent/include --libexecdir=/usr/sbin
Thread model: posix
gcc version 3.2 20020927 (prerelease)
C:\Documents and Settings\fwyzard\Desktop\test>g++ -o x.exe gplus.cpp
C:\Documents and Settings\fwyzard\Desktop\test>x
Start ACFEScnv: 13:42:29.138
End ACFEScnv: 13:42:29.138
Sorry I coudn't be of more help :-(
fwyzard
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Linux C++ Help
2002-12-06 1:51 Linux C++ Help Jayanta Narayan Choudhuri
2002-12-06 4:43 ` Andrea 'fwyzard' Bocci
@ 2002-12-06 4:59 ` Momchil Velikov
1 sibling, 0 replies; 5+ messages in thread
From: Momchil Velikov @ 2002-12-06 4:59 UTC (permalink / raw)
To: Jayanta Narayan Choudhuri; +Cc: gcc-help
>>>>> "Jayanta" == Jayanta Narayan Choudhuri <sss@cal.vsnl.net.in> writes:
Jayanta> 1. gcc -o x.exe jnc.c # WORKS
Jayanta> 2. gcc -o x.exe jnc.cpp # FAILS even though jnc.c
Jayanta> & jnc.cpp are identical
But are compiled as different languages, C++ does NOT implicitly
declare ``int strlen (...)''.
Jayanta> 3. g++ -o x.exe jnc.cpp # also FAILS
For the same reason.
Jayanta> 4. g++ -o x.exe gplus.cpp # also fails though I used the
Jayanta> recommended headers of C++
Same reason.
the above errors are NOT linking errors, too.
Adding ``#include <string.h>'' or ``#include <cstring>'' fixes the
above compilations.
Also, you should link C++ programs with the C++ compiler driver
``c++'' (or ``g++'') or, alternatively, specify the C++ libraries,
i.e., either
c++ -o xx jnc.cpp
or
gcc -o xx jnc.cpp -lstdc++
~velco
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: Linux C++ Help
@ 2002-12-06 14:06 Jayanta Narayan Choudhuri
0 siblings, 0 replies; 5+ messages in thread
From: Jayanta Narayan Choudhuri @ 2002-12-06 14:06 UTC (permalink / raw)
To: 'Andrea 'fwyzard' Bocci'; +Cc: gcc-help
[-- Attachment #1.1: Type: text/plain, Size: 1150 bytes --]
Dear Andrea
Thanks for your great help and suggestions. I have Red Hat 7.2 .
After your suggestion I included <string.h> and ultimately wrote the
small test program "jnctest.cpp" and got it to work. Apparently the
<string.h> should be before <string> as I experienced.
uname -a
Linux sss.sssdom 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686 unknown
ldd x.exe
libstdc++-libc6.1-1.so.2 => /usr/lib/libstdc++-libc6.1-1.so.2
(0x40032000)
libm.so.6 => /lib/libm.so.6 (0x40074000)
libc.so.6 => /lib/libc.so.6 (0x40097000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
comp.txt -- the output of g++ -v is attached.
_____
Once this little program worked I was able to link my main STL project
almost immediately and it produced perfect results.
Thanks a LOT for your tip.
Regards & Best Wishes
-jnc
PS. I will mechanically include always, right in the beginning, with g++
extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdarg.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <pthread.h>
}
[-- Attachment #1.2: Type: text/html, Size: 4718 bytes --]
[-- Attachment #2: jnctest.cpp --]
[-- Type: text/plain, Size: 1874 bytes --]
extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdarg.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <pthread.h>
}
#include <iostream>
#include <string>
class jnc
{ private:
char *s;
public:
jnc();
jnc(char *p);
void sets(char *p);
void sayhello();
};
jnc::jnc()
{
}
jnc::jnc(char *p)
{ s=new char[100];
strcpy(s,p);
}
void jnc::sets(char *p)
{ strcpy(s,p);
}
void jnc::sayhello()
{
cout << s << endl;
}
// convert to Upper Case
void MakeUpper(string& str)
{
int iterStr;
for(iterStr=0;iterStr<str.size();iterStr++)
str.replace(iterStr,1,1,toupper(str[iterStr]));
}
// ------------------------------- MAIN PROGRAM --------------------------------
int main(int argc, char *argv[])
{
int intIter;
struct timeb timebuffer;
char *timeline;
ftime( &timebuffer );
timeline = ctime( & ( timebuffer.time ) );
for(intIter=0;intIter<strlen(timeline);intIter++)
*(timeline+intIter)=toupper(*(timeline+intIter));
fprintf(stderr,"Start ACFEScnv: %.8s.%hu\n", timeline+11, timebuffer.millitm);
char *c;
c=(char *)malloc(10);
free((void *)c);
int i;
pthread_mutex_t fastmutex = PTHREAD_MUTEX_INITIALIZER;
i=pthread_mutex_lock(&fastmutex);
i=pthread_mutex_unlock(&fastmutex);
jnc j("Sushmita");
j.sayhello();
char s[]="J N Choudhuri";
j.sets(s);
j.sayhello();
string ss("uppercase");
MakeUpper(ss);
cerr << ss << endl;
ftime( &timebuffer );
timeline = ctime( & ( timebuffer.time ) );
fprintf(stderr,"End ACFEScnv: %.8s.%hu\n", timeline+11, timebuffer.millitm);
return 0;
} // END OF MAIN PROGRAM
[-- Attachment #3: comp.txt --]
[-- Type: text/plain, Size: 2318 bytes --]
Reading specs from /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc driver version 2.96 20000731 (Red Hat Linux 7.1 2.96-98) executing gcc version egcs-2.91.66
/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/cpp0 -lang-c++ -D__GNUG__=2 -D__EXCEPTIONS -v -iprefix /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/ -D__GNUC__=2 -D__GNUC_MINOR__=91 -D__GNUC_PATCHLEVEL__=66 -D__ELF__ -Dunix -Di386 -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__i386__ -D__linux__ -D__unix -D__i386 -D__linux -Asystem(posix) -D__NO_INLINE__ -Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_i386__ jnctest.cpp /tmp/cci3pZCj.ii
GNU CPP version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/include
/usr/include/g++-2
/usr/local/include
/usr/i386-glibc21-linux/include
/usr/lib/gcc-lib/i386-glibc21-linux/egcs-2.91.66/include
/usr/include
End of search list.
/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/cc1plus /tmp/cci3pZCj.ii -quiet -dumpbase jnctest.cpp -version -o /tmp/cc5AeBgn.s
GNU C++ version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386-glibc21-linux) compiled by GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release).
as -V -Qy -o /tmp/ccHOMgit.o /tmp/cc5AeBgn.s
GNU assembler version 2.11.90.0.8 (i386-redhat-linux) using BFD version 2.11.90.0.8
/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o x.exe /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/../../../crti.o /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/crtbegin.o -L/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96 -L/usr/i386-glibc21-linux/lib/gcc-lib -L/usr/lib/gcc-lib/i386-redhat-linux/2.96 -L/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/../../.. -L/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../.. /tmp/ccHOMgit.o -lstdc++ -lm -lgcc -lc -lgcc /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/crtend.o /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/../../../crtn.o
^ permalink raw reply [flat|nested] 5+ messages in thread
* RE: Linux C++ Help
@ 2002-12-06 14:06 Jayanta Narayan Choudhuri
0 siblings, 0 replies; 5+ messages in thread
From: Jayanta Narayan Choudhuri @ 2002-12-06 14:06 UTC (permalink / raw)
To: 'Momchil Velikov'; +Cc: gcc-help
[-- Attachment #1.1: Type: text/plain, Size: 1132 bytes --]
Dear ~velco
Thanks for your great help and suggestions.
After your suggestion I included <string.h> and ultimately wrote the
small test program "jnctest.cpp" and got it to work. Apparently the
<string.h> should be before <string> as I experienced.
uname -a
Linux sss.sssdom 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686 unknown
ldd x.exe
libstdc++-libc6.1-1.so.2 => /usr/lib/libstdc++-libc6.1-1.so.2
(0x40032000)
libm.so.6 => /lib/libm.so.6 (0x40074000)
libc.so.6 => /lib/libc.so.6 (0x40097000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
comp.txt -- the output of g++ -v is attached.
_____
Once this little program worked I was able to link my main STL project
almost immediately and it produced perfect results.
Thanks a LOT for your tip.
Regards & Best Wishes
-jnc
PS. I will mechanically include always, right in the beginning, with g++
extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdarg.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <pthread.h>
}
[-- Attachment #1.2: Type: text/html, Size: 4630 bytes --]
[-- Attachment #2: jnctest.cpp --]
[-- Type: text/plain, Size: 1874 bytes --]
extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdarg.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <pthread.h>
}
#include <iostream>
#include <string>
class jnc
{ private:
char *s;
public:
jnc();
jnc(char *p);
void sets(char *p);
void sayhello();
};
jnc::jnc()
{
}
jnc::jnc(char *p)
{ s=new char[100];
strcpy(s,p);
}
void jnc::sets(char *p)
{ strcpy(s,p);
}
void jnc::sayhello()
{
cout << s << endl;
}
// convert to Upper Case
void MakeUpper(string& str)
{
int iterStr;
for(iterStr=0;iterStr<str.size();iterStr++)
str.replace(iterStr,1,1,toupper(str[iterStr]));
}
// ------------------------------- MAIN PROGRAM --------------------------------
int main(int argc, char *argv[])
{
int intIter;
struct timeb timebuffer;
char *timeline;
ftime( &timebuffer );
timeline = ctime( & ( timebuffer.time ) );
for(intIter=0;intIter<strlen(timeline);intIter++)
*(timeline+intIter)=toupper(*(timeline+intIter));
fprintf(stderr,"Start ACFEScnv: %.8s.%hu\n", timeline+11, timebuffer.millitm);
char *c;
c=(char *)malloc(10);
free((void *)c);
int i;
pthread_mutex_t fastmutex = PTHREAD_MUTEX_INITIALIZER;
i=pthread_mutex_lock(&fastmutex);
i=pthread_mutex_unlock(&fastmutex);
jnc j("Sushmita");
j.sayhello();
char s[]="J N Choudhuri";
j.sets(s);
j.sayhello();
string ss("uppercase");
MakeUpper(ss);
cerr << ss << endl;
ftime( &timebuffer );
timeline = ctime( & ( timebuffer.time ) );
fprintf(stderr,"End ACFEScnv: %.8s.%hu\n", timeline+11, timebuffer.millitm);
return 0;
} // END OF MAIN PROGRAM
[-- Attachment #3: comp.txt --]
[-- Type: text/plain, Size: 2318 bytes --]
Reading specs from /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc driver version 2.96 20000731 (Red Hat Linux 7.1 2.96-98) executing gcc version egcs-2.91.66
/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/cpp0 -lang-c++ -D__GNUG__=2 -D__EXCEPTIONS -v -iprefix /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/ -D__GNUC__=2 -D__GNUC_MINOR__=91 -D__GNUC_PATCHLEVEL__=66 -D__ELF__ -Dunix -Di386 -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__i386__ -D__linux__ -D__unix -D__i386 -D__linux -Asystem(posix) -D__NO_INLINE__ -Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -D__tune_i386__ jnctest.cpp /tmp/cci3pZCj.ii
GNU CPP version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/include
/usr/include/g++-2
/usr/local/include
/usr/i386-glibc21-linux/include
/usr/lib/gcc-lib/i386-glibc21-linux/egcs-2.91.66/include
/usr/include
End of search list.
/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/cc1plus /tmp/cci3pZCj.ii -quiet -dumpbase jnctest.cpp -version -o /tmp/cc5AeBgn.s
GNU C++ version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release) (i386-glibc21-linux) compiled by GNU C version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release).
as -V -Qy -o /tmp/ccHOMgit.o /tmp/cc5AeBgn.s
GNU assembler version 2.11.90.0.8 (i386-redhat-linux) using BFD version 2.11.90.0.8
/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o x.exe /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/../../../crt1.o /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/../../../crti.o /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/crtbegin.o -L/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96 -L/usr/i386-glibc21-linux/lib/gcc-lib -L/usr/lib/gcc-lib/i386-redhat-linux/2.96 -L/usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/../../.. -L/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../.. /tmp/ccHOMgit.o -lstdc++ -lm -lgcc -lc -lgcc /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/crtend.o /usr/i386-glibc21-linux/lib/gcc-lib/i386-redhat-linux/2.96/../../../crtn.o
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-12-06 22:06 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-06 1:51 Linux C++ Help Jayanta Narayan Choudhuri
2002-12-06 4:43 ` Andrea 'fwyzard' Bocci
2002-12-06 4:59 ` Momchil Velikov
2002-12-06 14:06 Jayanta Narayan Choudhuri
2002-12-06 14:06 Jayanta Narayan Choudhuri
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).