Newbie Class Library Question

E

Ehtor

I'm trying to create a simple class library that I can statically link.
I'm new to c++.

If I append test code at the bottom of my class source file, compile and
link, the test works fine.

If, when I compile just the class, and create a library using ar and ranlib
and then compile my test program and link it to this library, the program
will seg fault at the closing bracket of the main routine.

I've googled this problem but I don't think I'm using the correct
terminology and have not been able to find a good solution.

I suspect I'm not creating the class library correctly or not compiling
something right. (btw, the class header contains just the class definition
and the public section).

Sorry for the basic question, but any help would be appreciated.

R
 
S

Sharad Kala

Ehtor said:
I'm trying to create a simple class library that I can statically link.
I'm new to c++.

Sorry but linking etc is not addressed by the C++ language. You can get a
peer reviewed answer on some newsgroup dedicated to your OS/compiler.

Sharad
 
J

John Harrison

Ehtor said:
I'm trying to create a simple class library that I can statically link.
I'm new to c++.

If I append test code at the bottom of my class source file, compile and
link, the test works fine.

If, when I compile just the class, and create a library using ar and ranlib
and then compile my test program and link it to this library, the program
will seg fault at the closing bracket of the main routine.

I've googled this problem but I don't think I'm using the correct
terminology and have not been able to find a good solution.

I suspect I'm not creating the class library correctly or not compiling
something right. (btw, the class header contains just the class definition
and the public section).

Sorry for the basic question, but any help would be appreciated.

If your problem is linking or compiling then it is not topical here. But if
your problem is a C++ bug then its on topic here. Its entirely possible that
a bug in your code would cause your program to behave properly in one
situation and crash in a different situation.

My bet is on a bug in your code, why not post it here.

john
 
M

Max Vasin

Ehtor said:
I'm trying to create a simple class library that I can statically link.
I'm new to c++.

If I append test code at the bottom of my class source file, compile and
link, the test works fine.

If, when I compile just the class, and create a library using ar and ranlib
and then compile my test program and link it to this library, the program
will seg fault at the closing bracket of the main routine.

I've googled this problem but I don't think I'm using the correct
terminology and have not been able to find a good solution.

I suspect I'm not creating the class library correctly or not compiling
something right. (btw, the class header contains just the class definition
and the public section).

Sorry for the basic question, but any help would be appreciated.

R
Have a look at libtool, its documentation explains step-by-step how to
create libraries.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,295
Latest member
EmilG1510

Latest Threads

Top