ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Basically, im just trying to count the number of words in a data file, where you have no idea how many words are actually there. The first function has not been completed, and is completely useless in its remedial stages, but somewhere, the following error occurs:
Code:
/usr/lib/crt1.o: In function `_start':
/usr/lib/crt1.o(.text+0x18): undefined reference to `main'
collect2: ld returned 1 exit status
My first guess is a library issue, but im not sure? Any ideas as to why this error occurs?
#include <stdio.h>
#include <stdlib.h>
void CreateWordList (char inputFileName [ ]);
int CountNumberOfWords (FILE* inputFile);
int main(int numberOfCommandLineArguments,
char *commandLineArguments [ ])
{
if (numberOfCommandLineArguments != 4)
{
fprintf (stderr, "\nError - ");
fprintf (stderr, "Incorrect number of command ");
fprintf (stderr, "line arguments!\n\n");
fprintf (stderr, "The user must enter command line ");
fprintf (stderr, "arguments in the following order:\n\n");
fprintf (stderr, "(Name of Executable File), ");
fprintf (stderr, "(Name of File Containing the Puzzle ");
fprintf (stderr, "Letters),\n(Name of File Containing ");
fprintf (stderr, "the List of Words to Try to Find), ");
fprintf (stderr, "and\n(Name of Output File in Which ");
fprintf (stderr, "to Write the Answers)\n\n");
fprintf (stderr, "Please try again!\n\n");
exit (-1);
}
CreateWordList (commandLineArguments [2]);
return 0;
}
But this should have no impact on the error because I am simply doing a gcc -Wall -ansi of function.c, which are the functions posted on my last post. The main function is simply doing nothing at this point, but checking for command line arguments.
Variable names are not interdependent on execution. It's the reason in java for variances in the static main function, which allows it to compile universally without problems.
For instance, static main(String [ ] args) can be the same as static main(String[ ] anyvariablename), and will work without a problem.
Think of it like changing basic variable names, they are just parameters in a function, which happens to be main, so thats not the problem.
Would there be any issue without passing this function as integer, I got it to work as a void function, and im returning everything correctly and such. It's kind of awkward. Any ideas?
I'm guessing your main is in a separate .c/.cpp file. There are a couple of steps in building an executable with C/C++. The first step compiles to object files. The 2nd step links those into the final binary. Your problem is that you do not have the object file which contains your main function, so the linker is giving you an undefined reference error. Now, assuming that your main is in main.c, just add main.c to your command line parameters. Typically the 2 step process is hidden in these cases.
If for some reason you wanted to do the 2 steps yourself, you could use the -c parameter. That will create the intermediate .o files, and then you can link the .o files together with an additional call to gcc/g++.
This differs from Java, where you can just call javac on a single .java file and the javac compiler will find all other files that java file is dependent upon.
This problem was taking care of, it was a pre-post to the read number of lines post. It basically involved library issues and other small things like that!
I found one unorthodox solution by copy pasting the entire contents of main.cpp into the conversionform.ui.h file of the application, given below after pasting it:-
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/*1) conversionform.ui.h
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
#include <qvalidator.h>
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/* Pasted from main.cpp:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.