开发者

Compilation problem in the standard x86_64 libraries

I am having trouble compiling a program I have written. I have two different files with the same includes but only one generates the following error when compiled with g++

/usr/lib/gcc/x86_64-linux-gnu/4.4.1/../../../../lib/crt1.o: In function `_start':
/build/buildd/eglibc-2.10.1/csu/../sysdeps/x86_64/elf/start.S:109: undefined reference to `main'
collect2: ld returned 1 exit status

The files I am incl开发者_如何学Pythonuding in my header are as follows:

#include <google/sparse_hash_map>
using google::sparse_hash_map;

#include <ext/hash_map>
#include <math.h>
#include <iostream>
#include <queue>
#include <vector>
#include <stack>

using std::priority_queue;
using std::stack;
using std::vector;

using __gnu_cxx::hash_map;
using __gnu_cxx::hash; 

using namespace std;

Searching the internet for those two lines hasn't resulted in anything to help me. I would be very grateful for any advice. Thank you


To build two separate programs you need both source files to define main() function.

To build a single program out of two source files - first compile each file with -c options (compile only) - you will get two .o files, then link these files together. Something like this:

$ g++ -Wall -pedantic -ggdb -O -c -o module0.o module0.cpp
$ g++ -Wall -pedantic -ggdb -O -c -o module1.o module1.cpp
$ g++ -Wall -pedantic -ggdb -O -o prog module0.o module1.o

to build binary prog from two source files.

If you need to link with some library, you'll have to point compiler to it's headers with -I and to objects with -L flags, then tell the linker to actually reference the library with -l.

Hope this helps.


You need a main function and you don't have one. If you do have a main function, show more code please.


It looks like main is not defined. Do you have one defined for your second program? Can you post more details about the source body that fails to link?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜