473,976 Members | 37,178 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

compiling a c++ class library

I've been working on vector/matrix/PRNG class libraries for years, but
I never got around to figuring out how to make them into libraries; I'm
a statistician, not a computer scientist. So, for this example, I'm
using g++ 4.0.0 on Solaris(SPARC) 9, if that makes any difference.
Everything worked fine for the Vector libary, build (Makefile excerpt):

#create shared library in PWD
#with GNU ld
#SHARED=-shared
#with Sun ld
SHARED=-Xlinker -G

#GNU C++ compiler and flags
CXX=g++-4.0.0 -g

#GSL/math libraries
LIBS=-lgsl -lgslcblas -lm

libvector.so : vector.cxx vector.hxx Makefile
$(CXX) -nostartfiles $(SHARED) -o $@ vector.cxx $(LIBS)

vector_main.out : vector_main.cxx libvector.so
$(CXX) -o $@ vector_main.cxx $(LIBS) -lvector
./$@

But, the same thing does not work for the Matrix library. It's not the
code as far as I can tell, because simpy doing an #include "matrix.cxx "
works:
libmatrix.so : matrix.cxx matrix.hxx Makefile
$(CXX) -nostartfiles $(SHARED) -o $@ matrix.cxx $(LIBS)

matrix_main.out : matrix_main.cxx libmatrix.so libvector.so
$(CXX) -o $@ matrix_main.cxx $(LIBS) -lvector -lmatrix
./$@

make matrix_main.out
g++-4.0.0 -g -nostartfiles -Xlinker -G -o libmatrix.so matrix.cxx -lgsl
-lgslcblas -lm
g++-4.0.0 -g -o matrix_main.out matrix_main.cxx -lgsl -lgslcblas -lm
-lvector -lmatrix
Undefined first referenced
symbol in file
Matrix::operato r=(Matrix) /var/tmp//ccqgGJUa.o
Matrix::inverse (double) /var/tmp//ccqgGJUa.o
Matrix::Matrix( unsigned int, unsigned int, double,
....)/var/tmp//ccqgGJUa.o
Matrix::Matrix( Matrix const&) /var/tmp//ccqgGJUa.o
Matrix::operato r-() /var/tmp//ccqgGJUa.o
Matrix::~Matrix () /var/tmp//ccqgGJUa.o
operator*(Matri x const&, Matrix const&)/var/tmp//ccqgGJUa.o
operator<<(std: :basic_ostream< char, std::char_trait s<char> >&,
Matrix)/var/tmp//ccqgGJUa.o
ld: fatal: Symbol referencing errors. No output written to
matrix_main.out
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `matrix_main.ou t'

Any ideas?

Thanks, Rodney

Jul 23 '05 #1
5 1848
rs******@mcw.ed u wrote:
make matrix_main.out
g++-4.0.0 -g -nostartfiles -Xlinker -G -o libmatrix.so matrix.cxx
-lgsl -lgslcblas -lm
g++-4.0.0 -g -o matrix_main.out matrix_main.cxx -lgsl -lgslcblas
-lm -lvector -lmatrix
Undefined first referenced
symbol in file
Matrix::operato r=(Matrix) /var/tmp//ccqgGJUa.o
Matrix::inverse (double) /var/tmp//ccqgGJUa.o
Matrix::Matrix( unsigned int, unsigned int, double,
...)/var/tmp//ccqgGJUa.o
Matrix::Matrix( Matrix const&) /var/tmp//ccqgGJUa.o
Matrix::operato r-() /var/tmp//ccqgGJUa.o
Matrix::~Matrix () /var/tmp//ccqgGJUa.o
operator*(Matri x const&, Matrix const&)/var/tmp//ccqgGJUa.o
operator<<(std: :basic_ostream< char, std::char_trait s<char> >&,
Matrix)/var/tmp//ccqgGJUa.o
ld: fatal: Symbol referencing errors. No output written to
matrix_main.out
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `matrix_main.ou t'


I think thats not a C++ problem, its a linker problem. Thus its very
system depending and has not much to do with C++.

First make sure the libmatrix.so is created. Check for existence and
check the contents (nm -C libmatrix.so should do this job). Next
make sure your linker uses the right libs, maybe by adding a -L
switch.

And at last check the order of the libs. If a lib uses symbols from
another lib, it should stand before on the commandline. Does
libvector make calls into libmatrix? I assume a better order for you
linker command line would be:

-lvector -lmatrix -lgsl -lgslcblas -lm

Mathias
Jul 23 '05 #2
Hi Mathias:

Thanks for your response. I agree you with you that it is a linker
problem and not a C++ problem. However, linking is an important part
of using C++, so someone must know how this is done. I tried
everything that you mentioned and alot more. Nothing has helped yet.
What confuses me is that the vector and matrix linking processes are
analogous; vector works, matrix fails. What's different? Not sure.

Thanks, Rodney

Jul 23 '05 #3
rsparapa wrote:
Thanks for your response. I agree you with you that it is a linker
problem and not a C++ problem. However, linking is an important part
of using C++, so someone must know how this is done.


Posting to the narrowest possible newsgroup - one that covers your
compiler's linker - will get you the best answers. More people on that list
will be qualified to review any answers you get.

--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand
Jul 23 '05 #4
try a -L. -R. before your -lmatrix and/or compiling the library source
with -fPIC.

Jul 23 '05 #5
> Matrix::operato r=(Matrix) /var/tmp//ccqgGJUa.o

Please check if in matrix.cxx you really define operator= for Matrix
object, which takes const Matrix& argument. My guess is you are
accidentally redefining Vector operator=.
rs******@mcw.ed u wrote:
I've been working on vector/matrix/PRNG class libraries for years, but
I never got around to figuring out how to make them into libraries; I'm
a statistician, not a computer scientist. So, for this example, I'm
using g++ 4.0.0 on Solaris(SPARC) 9, if that makes any difference.
Everything worked fine for the Vector libary, build (Makefile excerpt):

#create shared library in PWD
#with GNU ld
#SHARED=-shared
#with Sun ld
SHARED=-Xlinker -G

#GNU C++ compiler and flags
CXX=g++-4.0.0 -g

#GSL/math libraries
LIBS=-lgsl -lgslcblas -lm

libvector.so : vector.cxx vector.hxx Makefile
$(CXX) -nostartfiles $(SHARED) -o $@ vector.cxx $(LIBS)

vector_main.out : vector_main.cxx libvector.so
$(CXX) -o $@ vector_main.cxx $(LIBS) -lvector
./$@

But, the same thing does not work for the Matrix library. It's not the
code as far as I can tell, because simpy doing an #include "matrix.cxx "
works:
libmatrix.so : matrix.cxx matrix.hxx Makefile
$(CXX) -nostartfiles $(SHARED) -o $@ matrix.cxx $(LIBS)

matrix_main.out : matrix_main.cxx libmatrix.so libvector.so
$(CXX) -o $@ matrix_main.cxx $(LIBS) -lvector -lmatrix
./$@

make matrix_main.out
g++-4.0.0 -g -nostartfiles -Xlinker -G -o libmatrix.so matrix.cxx -lgsl
-lgslcblas -lm
g++-4.0.0 -g -o matrix_main.out matrix_main.cxx -lgsl -lgslcblas -lm
-lvector -lmatrix
Undefined first referenced
symbol in file
Matrix::operato r=(Matrix) /var/tmp//ccqgGJUa.o
Matrix::inverse (double) /var/tmp//ccqgGJUa.o
Matrix::Matrix( unsigned int, unsigned int, double,
...)/var/tmp//ccqgGJUa.o
Matrix::Matrix( Matrix const&) /var/tmp//ccqgGJUa.o
Matrix::operato r-() /var/tmp//ccqgGJUa.o
Matrix::~Matrix () /var/tmp//ccqgGJUa.o
operator*(Matri x const&, Matrix const&)/var/tmp//ccqgGJUa.o
operator<<(std: :basic_ostream< char, std::char_trait s<char> >&,
Matrix)/var/tmp//ccqgGJUa.o
ld: fatal: Symbol referencing errors. No output written to
matrix_main.out
collect2: ld returned 1 exit status
*** Error code 1
make: Fatal error: Command failed for target `matrix_main.ou t'

Any ideas?

Thanks, Rodney

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2701
by: Mike S. | last post by:
Hello, Has anyone had success compiling the informixdb-1.3 module under python 2.2? It seems the absense of makefile.pre.in in python 2.2 causes the break under py2.2. Is there an easy way around this. I've heard rumors of a manual method, but have been unable to track down details. Any help is very much appreciated. Thanks in advance, Mike
7
5143
by: Steven T. Hatton | last post by:
Is there anything that gives a good description of how source code is converted into a translation unit, then object code, and then linked. I'm particularly interested in understanding why putting normal functions in header files results in multiple definition errors even when include guards are used. -- STH Hatton's Law: "There is only One inviolable Law" KDevelop: http://www.kdevelop.org SuSE: http://www.suse.com Mozilla:...
3
2096
by: Tron Thomas | last post by:
Given the following code: #include <vector> #include <algorithm> #include <functional> class Value { public: explicit Value(int value) : m_value(value) {}
4
11380
by: Aaron Queenan | last post by:
When I build a C++ library to .NET using the managed C++ compiler, I get the following error message: Linking... LINK : error LNK2020: unresolved token (0A000005) _CrtDbgReport LINK : error LNK2020: unresolved token (0A000007) memset LINK : error LNK2020: unresolved token (0A000008) free LINK : error LNK2020: unresolved token (0A00000A) atexit LINK : error LNK2020: unresolved token (0A000028) wcscpy LINK : error LNK2020: unresolved...
1
1173
by: pataN | last post by:
I use csc /t:library scanControl.dll. Here I got some errors telling me that the compiler can't find the class library dll:s that I have referenced in my windows control project. I have added references to the two classes and I use the using statements. Isn't that enough? After compiling the control I will put it in the virtual directory of IIS so that other web users can download it. My question here is how do I do to distribute more than...
1
1917
by: Jim Heavey | last post by:
Hello, trying to round out my knowlege here about compiling. To date I have used VS.Net to do all my compiling "majically", but I want to understand how to do it on my own, should the need ever arrise. It has been suggested to me that I should use the following pattern when compiling my programs, but I am not sure I understand the "pattern", Try creating a text file along the following lines where the /r are the dlls you are...
3
1038
by: Hugh Janus | last post by:
Hi all, I have added a class library project to my VB solution. All works fine but when I compile the project, the compiler creates an external DLL file. What I would rather it do is compile the class library project into the main VB .exe app that I am compiling. Is this possible? If so, how? Thanks
0
2549
by: Pucca | last post by:
Hi I'm using vs2005. I am getting a bunch of compiler warnings after I made some changes to my code that was compiling clean. I'm also getting memory errors when I run my program and it's pinvoking some C++ code, which was working also fine before. I wonder if these warning are causing the problem. I would appreciate some help or suggestions on how to correct these. Thanks. Warning 37 At least one of the arguments for...
8
2217
by: WebSnozz | last post by:
I have an application written in C that does a lot of low level stuff. It does a lot of things like casting from void*'s. I want to create a new GUI for it in either C# or MC++, but reuse the existing code. The options I've considered so far: 1. Create a new MC++ GUI project and add the *.c files to them and mark them with pragma unamanged. However, the /clr option does not compile *.c files, so I rename them to *.cpp, and now they...
2
1991
by: stevenruiz | last post by:
Hi Everyone, The Strings.h has the function Get_Line which is defined and the error is shown below: Strings.h: void get_line( istream & );
0
10355
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10171
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
11573
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10908
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8462
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7604
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6558
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3761
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.