- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I hope someone can help me. I'm a newbie in linux and programming and it's taking me a lot of time to go forward with my project. I have to execute a makefile which involves the compilation of two sections of a program: the main program is in Fortran 77, for which I use the ifort compiler, and the input-output module (programio.cpp) is in C++, for which I use the intel compiler. The execution of the makefile leads to the following error:
icc -IC:/usr/local/inputdata/include -O3 -o programio-std.obj -c programio.cpp
programio.cpp(3251): error: identifier "strchr" is undefined
if (strchr(buff, '\\n')) *strchr(buff, '\\n') = '\\0';
^
compilation aborted for programio.cpp (code 2)
make: *** [prgramio-std.obj] Error 2
I have the string.h file, as well as the strchr.al, but they doesn't seem to be in the right place, and I tried to copi them in other places and it's still not working. Do you know where exactly does the program read the libraries from? It seems to be quite stupid, but it's taking me days to sort that out, and I'm still not able, so any help will be more thant welcome.
Thank you in advance!!
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am providing the sample below that I tried out.
$ cat tstcase.cpp
#include
#include
int main()
{
char buf[]="Hero jump off the plane\n";
printf("%s\n", buf);
if (strchr(buf, '\n'))
*strchr(buf,'\n')='\0';
printf("%s\n", buf);
return 0;
}
$ icc -V
Intel C Intel 64 Compiler XE for applications running on Intel 64, Vers
ion 12.0.1.107 Build 20101116
Copyright (C) 1985-2010 Intel Corporation. All rights reserved.
$ icc tstcase.cpp
$ ./a.out
Hero jump off the plane
Hero jump off the plane
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I won't be able to try it before next week (I'm out of UK and for some reason I'm not being able to access the VPN of the college, where the compilers are). However, I tried another program a friend send to me a couple of days ago, and it worked perfectly with gcc...
Compiling just the c++ part leads to the same error, so it's obviously not a problem of the makefile, and the program has worked properly to other people...so I don't what else can it be..
Any more ideas?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This looks wrong for Linux:
-IC:/usr/local/inputdata/include
Linux doesn't have drives like "C:/"
This should probably be:
-I/usr/local/inputdata/include
or as Om stated the directory containing the string.h header file should already be included by icpc.
Are you sure you have an #include
Using the -E -P options should tell you where the string.h header is located and what is in it, i.e. why there's no prototype for strchr().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for your answer. I already changed the directory in the makefile and checked that the #include
The fist thing didn't change anything, and the last lead to hundreds of errors I dind't have before, most of them "undefined references"
I also verified with another colleague that the libraries were in the correct place, so that shouldn't be the problem.
This is really driving me crazy, because I need to have it solved by the end of the month, but I'm not going forward with it at all.
Help me please!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You mean #include
You shouldn't need to also say #include
So when you looked at the preprocessed header file what did you see? Where was the string.h file coming from? This is what I see:
sptxl8-541> cat t.cpp
#include
sptxl8-542> icpc -E t.cpp | more
# 1 "t.cpp"
# 1 "/usr/include/string.h" 1 3
...
As you can see my string.h is coming from /usr/include. The strchr prototype should be in there...
sptxl8-543> icpc -E t.cpp >t.E
sptxl8-544> grep strchr t.E
extern char *strchr (__const char *__s, int __c)
extern char *strchrnul (__const char *__s, int __c)
Judy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for that, I really need to learn the basics with linux..;-P
The string library is called by #include
I tried:
cat programio.cpp
but the program is really very long, so I can't copy everything here!
After that, I got
[ascotilla@lb-ascotilla-lap bin]$ icpc -E programio.cpp | more
# 1 "lpjio.cpp"
# 1 "/usr/include/c++/4.4.4/iostream" 1 3
(...)
I haven't seen the
I also tried:
[ascotilla@lb-ascotilla-lap bin]$ icpc -E programio.cpp >programio.E
[ascotilla@lb-ascotilla-lap bin]$ grep strchr programio.E
and I got:
if (strchr(buff, '\n')) *strchr(buff, '\n') = '\0';
which is the only line in the whole program that is driving me crazy..;-P
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
int count_occ(char* a, char* b)
{
int la =strlen(a);
int lb =strlen(b);
int j;
int x;
int k;
int noc = 0;
for (j= 0;j <= la-1 ;j++)
{
x=0;
if (a
for (k=j; k <= j +lb-1 ; k++)
if (a
{
x++;
}
if (x == lb)
{
noc++;
}
}
return noc;
}
if (count_occ(buff,"\n")==0)
{
}
Add this function you take your money end month.......
with more time to resolve your strange
Sometimes bugs very very strange....
I think is not header is absent
is an fault form interpreted resulting this message header absent..
Difficult to help you more side
is bug relational
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Please do the following to see where the string header is coming from.
grep string programio.E | grep "#"
This is what I see (I'm using g++ 4.1.1, looks like you're using 4.4.4):
sptxl8-785> grep string t.E | grep "#"
# 1 "/usr/include/c++/4.1.1/string" 1 3
# 45 "/usr/include/c++/4.1.1/string" 2 3
# 1 "/usr/include/c++/4.1.1/bits/stringfwd.h" 1 3
# 46 "/usr/include/c++/4.1.1/string" 2 3
# 1 "/usr/include/c++/4.1.1/cstring" 1 3
# 51 "/usr/include/c++/4.1.1/cstring" 2 3
# 1 "/usr/include/string.h" 1 3
# 34 "/usr/include/string.h" 2 3
# 119 "/usr/include/string.h" 2 3
# 152 "/usr/include/string.h" 3
# 164 "/usr/include/string.h" 3
# 279 "/usr/include/string.h" 3
# 419 "/usr/include/string.h" 3
# 53 "/usr/include/c++/4.1.1/cstring" 2 3
# 77 "/usr/include/c++/4.1.1/cstring" 3
# 47 "/usr/include/c++/4.1.1/string" 2 3
# 48 "/usr/include/c++/4.1.1/string" 2 3
# 52 "/usr/include/c++/4.1.1/string" 2 3
# 1 "/usr/include/c++/4.1.1/bits/basic_string.h" 1 3
# 46 "/usr/include/c++/4.1.1/bits/basic_string.h" 2 3
# 53 "/usr/include/c++/4.1.1/string" 2 3
# 56 "/usr/include/c++/4.1.1/string" 2 3
# 1 "/usr/include/c++/4.1.1/bits/basic_string.tcc" 1 3
# 57 "/usr/include/c++/4.1.1/string" 2 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This is what I got:
# 1 "/usr/include/c++/4.4.4/bits/stringfwd.h" 1 3
# 74 "/usr/include/c++/4.4.4/bits/stringfwd.h" 3
# 1 "/usr/include/c++/4.4.4/string" 1 3
# 44 "/usr/include/c++/4.4.4/string" 2 3
# 47 "/usr/include/c++/4.4.4/string" 2 3
# 51 "/usr/include/c++/4.4.4/string" 2 3
# 1 "/usr/include/c++/4.4.4/bits/basic_string.h" 1 3
# 44 "/usr/include/c++/4.4.4/bits/basic_string.h" 2 3
# 488 "/usr/include/c++/4.4.4/bits/basic_string.h" 3
# 547 "/usr/include/c++/4.4.4/bits/basic_string.h" 3
# 829 "/usr/include/c++/4.4.4/bits/basic_string.h" 3
# 895 "/usr/include/c++/4.4.4/bits/basic_string.h" 3
# 1014 "/usr/include/c++/4.4.4/bits/basic_string.h" 3
# 1058 "/usr/include/c++/4.4.4/bits/basic_string.h" 3
# 1514 "/usr/include/c++/4.4.4/bits/basic_string.h" 3
# 2688 "/usr/include/c++/4.4.4/bits/basic_string.h" 3
# 54 "/usr/include/c++/4.4.4/string" 2 3
# 1 "/usr/include/c++/4.4.4/bits/basic_string.tcc" 1 3
# 240 "/usr/include/c++/4.4.4/bits/basic_string.tcc" 3
# 57 "/usr/include/c++/4.4.4/string" 2 3
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I think that as the proram is quite big and complicated, it has had already problems, which is quite anoying.
What's the program you sent me for?? I'm sorry I didn'te get it
Cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
sorry i am unable to translate correctly an first part of your last answer
you have wrote first exchange
I hope someone can help me. I'm a newbie in linux and programming
and it's taking me a lot of time to go forward with my project.
I have to execute a makefile which involves the compilation
of two sections of a program: the main program is in Fortran 77,
for which I use the ifort compiler, and the input-output module (programio.cpp)
is in C++, for which I use the intel compiler.
The execution of the makefile leads to the following error)
(if (strchr(buff, '\n')) *strchr(buff, '\n') = '\0';)
Function i have wrote to you could result exactly same value in other form
for resolve where you are locked.without call to (strchr)
for find if return line("\n") is present in buff..
(What's the program you sent me for?? I'm sorry I didn'te get it)
if noc return zero, is (return line) is not present in buff..
Regards
nb:
strch work perfectly all (g++ and icpc version) ,only your (input-output module)
is wrong or obsolete.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If you do a "man strchr" then you will see it's in the header file
It looks like the header file
If you need the prototype for the strchr function you need to either
(1) #include
or
(2) #include
Judy

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page