LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 04-18-2013, 04:57 AM   #1
arungpillai09054
LQ Newbie
 
Registered: Nov 2012
Posts: 7

Rep: Reputation: Disabled
How to overcome the following error?


I got the following code,
Code:
    int main (int argc,char *argv[])
    {
      struct sha512_ctx ctx;
      char sum[64];
      int result = 0;
      int cnt;
    
      for (cnt = 0; cnt < (int) ntests; ++cnt)
        {
          sha512_init_ctx (&ctx);
          sha512_process_bytes (tests[cnt].input, strlen (tests[cnt].input), &ctx);
          sha512_finish_ctx (&ctx, sum);
          if (memcmp (tests[cnt].result, sum, 64) != 0)
    	{
    	  printf ("test %d run %d failed\n", cnt, 1);
    	  result = 1;
    	}
    
          sha512_init_ctx (&ctx);
          for (int i = 0; tests[cnt].input[i] != '\0'; ++i)
    	sha512_process_bytes (&tests[cnt].input[i], 1, &ctx);
          sha512_finish_ctx (&ctx, sum);
          if (memcmp (tests[cnt].result, sum, 64) != 0)
    	{
    	  printf ("test %d run %d failed\n", cnt, 2);
    	  result = 1;
    	}
        }
      char buf[1000];
      memset (buf, 'a', sizeof (buf));
      sha512_init_ctx (&ctx);
      for (int i = 0; i < 1000; ++i)
        sha512_process_bytes (buf, sizeof (buf), &ctx);
      sha512_finish_ctx (&ctx, sum);
      static const char expected[64] =
        "\xe7\x18\x48\x3d\x0c\xe7\x69\x64\x4e\x2e\x42\xc7\xbc\x15\xb4\x63"
        "\x8e\x1f\x98\xb1\x3b\x20\x44\x28\x56\x32\xa8\x03\xaf\xa9\x73\xeb"
        "\xde\x0f\xf2\x44\x87\x7e\xa6\x0a\x4c\xb0\x43\x2c\xe5\x77\xc3\x1b"
        "\xeb\x00\x9c\x5c\x2c\x49\xaa\x2e\x4e\xad\xb2\x17\xad\x8c\xc0\x9b";
      if (memcmp (expected, sum, 64) != 0)
        {
          printf ("test %d failed\n", cnt);
          result = 1;
        }
    
      for (cnt = 0; cnt < ntests2; ++cnt)
        {
          char *cp = sha512_crypt (tests2[cnt].input, tests2[cnt].salt);
    
          if (strcmp (cp, tests2[cnt].expected) != 0)
    	{
    	  printf ("test %d: expected \"%s\", got \"%s\"\n",
    	   	  cnt, tests2[cnt].expected, cp);
    	  result = 1;
    	}
        }
    
      if (result == 0)
        puts ("all tests OK");
    
      return result;
    }
While executing the above code, I got the following error,

Quote:
/usr/lib/gcc/x86_64-linux-gnu/4.6/../../../x86_64-linux-gnu/crt1.o: In
function `_start': (.text+0x20): undefined reference to `main'
collect2: ld returned 1 exit status
Can anyone help us to overcome this run-time error?
 
Old 04-18-2013, 07:04 AM   #2
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,146

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
I think you would need to give us more info:
how did you compile it, how it was executed, what os, what compiler, what else....
 
Old 04-18-2013, 08:39 AM   #3
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,934

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
> While executing the above code, I got the following error,

You didn't execute anything, you got a linkage error. Most likely the compilation wasn't successful either (your code is incomplete, so I couldn't check it).
 
Old 04-23-2013, 03:25 AM   #4
arungpillai09054
LQ Newbie
 
Registered: Nov 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
To Pan64,

os : 64bit ubuntu 12.04
compiler : gcc

sir, I got this code from internet. but I didn't know how to give a string as input. At first, I thought it was due to not providing any return value. But it also showed the same kind of error.
 
Old 04-23-2013, 03:44 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,934

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
Good Sir, the code you pasted in is incomplete, and you didn't show the command you used. Everything else is perfect.
 
Old 04-23-2013, 03:46 AM   #6
arungpillai09054
LQ Newbie
 
Registered: Nov 2012
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
Good Sir, the code you pasted in is incomplete, and you didn't show the command you used. Everything else is perfect.
sir, I used gcc command.
 
Old 04-23-2013, 03:48 AM   #7
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,146

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
Quote:
Originally Posted by arungpillai09054 View Post
sir, I used gcc command.
It is not an answer. Everyone should use gcc to compile code. The question is how did you use? What was the command you executed and what was the output.
 
  


Reply

Tags
compilation, cprogramming, encryption


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to overcome the following error? arungpillai09054 Linux - Newbie 3 04-19-2013 04:22 PM
Using 'noapic' to overcome black screen woodpecka_04 Fedora - Installation 3 05-14-2007 01:34 PM
How to overcome symbol lookup error? unclesam Linux - Newbie 2 02-10-2006 03:50 AM
overcome chmod ohovus Linux - Security 4 11-29-2005 01:41 PM
imp...!grub error 23 how to overcome farhan Linux - General 0 03-11-2003 05:30 PM


All times are GMT -5. The time now is 03:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration