Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29276 Discussions

programio.cpp(3251): error: identifier "strchr" is undefined

ascotilla
Beginner
2,969 Views
Hi all,

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 don't know what is a strchr identifier for, but is not in the program nor in any of my files. Should I download it from any site?

Thank you in advance!!
0 Kudos
6 Replies
mecej4
Honored Contributor III
2,969 Views
The command man strchr will tell you about strchr().

The function strchr is declared in string.h, and is in the standard C runtime library. The appropriate header file needs to be included in programio.cpp if not done already.

To link Fortran and C/C++ objects together, compile the C parts with the C compiler, and let the Fortran compiler do the linking.
0 Kudos
ascotilla
Beginner
2,969 Views
Hi mecej4,

Thank a lot for your answer. The makefile should make the compilation and linking of both parts of the program. It has already worked for others, but I don't know why am I having so many problems with it. I finally found the file strchr.al in /usr/lib64/perl5/5.10.0/x86_64-linux-thread-multi/auto/POSIX/. However, copying the file, or even the whole libraries, to the folder defined in the makefile, or in the folder where the program is it always leads to the same error. The header is also included in the program, so that shouldn't be the problem.

Any more ideas??

Thanks



0 Kudos
ascotilla
Beginner
2,969 Views
Following the advice of a friend, I tried to compile a program in C which was different from programio.cpp but has also one line involving the "strchr" identifier...and surprisingly it worked!! but I still have the problem with my program, so please, help!!

As the example he sent me was in C and not in C++, I dived through the net to look for C++ examples. I tried many of them, and all led to an error. The last one I tried is from the Intel C++ Compiler User's Manual:

#include
#include
#define MAX 85
int main(void)
{
char string[MAX + 1];
char ch = w;
char *first;
int pos;
strcpy(string, "Bah, bah, black sheep Have you any wool? ");
strcat(string, "Yes, Sir! Yes, Sir! Three bags full.");
first = strchr(string, ch);
pos = first - string + 1;
printf("\nIn the string \n\n%s\n\nthe character %c "
"was first found at position %d\n", string, ch, pos);
return 0;
}

And the error I got was:

prueba.cpp(7): error: unrecognized token
char ch = w;
^

prueba.cpp(7): error: expected an expression
char ch = w;
^

prueba.cpp(7): error: unrecognized token
char ch = w;
^

compilation aborted for prueba.cpp (code 2)


All of them were examples of the use of "strchr", so I start to think that it is a problem of C++. What can be missing??

Thanks in advance!

0 Kudos
IanH
Honored Contributor III
2,969 Views
You are using the wrong single quote character around the 'w' literal. This is possibly because you have used "cut and paste" to create the source file. You want the one that corresponds to ascii character 27 - same key (but unshifted) as the double quote on a US style keyboard.

Note that you have been posting in the ifort for Windows forum.

The forum software has an "Insert code using SyntaxHighlighter" toolbar icon (it looks like a little orange highlighter or pencil) that is very handy for pasting code and error messages. Avoids misalignment issues from line to line due to the use of proportional fonts.
0 Kudos
ascotilla
Beginner
2,969 Views
Thank you IanH, I really haven't notice that I was in ifort for windows! I'll try to post this also in the linux analogue. What you're saying will perfectly explain why none of the cpp programs I was trying to compile actually were compiled. Unfortunately, I still have my problem with the strchr, which is what really is driving me crazy...I don't know what else can I try!!
0 Kudos
IanH
Honored Contributor III
2,969 Views
Quoting ascotilla
The header is also included in the program, so that shouldn't be the problem.

mecej4 didn't suggest , he suggested . The first one is a C++ standard header, the second is a C standard header. They declare different things.

0 Kudos
Reply