Thread: Compiling with gcc

  1. #1
    Registered User
    Join Date
    Mar 2002

    Compiling with gcc

    Hi Im brandnew to both this board as to programming C I tried to write this program
    with redhat 6.2

    #include <stdio.h>
    #include <string.h>

    char str1[] ={ 'A',' ',
    'S','T','R','I','N','G',' ',
    char str2[] = "Another string constant";
    char *ptr_str = "Assign a string to a pointer";

    printf("The length of str1 is: %d bytes\n",strlen(str1));
    printf("The length of str2 is: %d bytes\n".strlen(str2));
    printf("The length of the string assigned to ptr_str is: %d bytes\n",strlen(ptr_str));

    return 0;

    and compile it in a executable with this command

    gcc -Wall -o test test.c

    this is my error

    request for member 'strlen' in something not a structure or union.

    Now I figured out that when i want to include the lib math.h I need to add -lm at the end of the commando, but I dont know what I need to add to include the string.h, I know its probably something real stupid. But I could find the answer anywhere

  2. #2
    You have a typo...

    On line 13 of your code, you typed in a period instead of a comma before the 'strlen'... that is why it did not recognize the function.

    I compiled it on a linux and it worked fine...

    Good luck

  3. #3
    Registered User
    Join Date
    Mar 2002
    Nooo, the horror aarg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GCC: Compiling with both static and shared libraries
    By eatwithaspork in forum C Programming
    Replies: 4
    Last Post: 06-23-2008, 01:48 PM
  2. GCC error in compiling
    By JFonseka in forum C Programming
    Replies: 11
    Last Post: 10-15-2007, 04:57 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. problems compiling in gcc
    By ra_mer in forum C Programming
    Replies: 6
    Last Post: 09-04-2006, 09:13 PM
  5. Compiling in Linux - GCC
    By gqchynaboy in forum C Programming
    Replies: 15
    Last Post: 03-02-2005, 12:15 PM