• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
jamesleighe

Making a Static Lib in Linux

7 posts in this topic

(c++, clang++, debian: wheezy)

 

I'm trying to build and link to a static library in Linux (which I have never programmed in before).

 

The problem I am having is that when I try to link to my library it tells me:

"../libsophia/build/libsophia.a: could not read symbols: Archive has no index; run ranlib to add one"

 

Then, when I try to run "nm libsophia.a" I get:

nm: sa_math.o: File format not recognized
nm: sa_sophia.o: File format not recognized
nm: sa_stringtools.o: File format not recognized
nm: sa_string.o: File format not recognized
nm: sa_baseapplication.o: File format not recognized
nm: sa_random.o: File format not recognized
 
So, I must at least be compiling it wrong!
 
Here are my makefiles:
(My Static Library)
	clang_compile = clang++ -std=c++0x -S

all:
	$(clang_compile) sa_math.cpp		-o build/sa_math.o
	$(clang_compile) sa_sophia.cpp		-o build/sa_sophia.o
	$(clang_compile) sa_stringtools.cpp	-o build/sa_stringtools.o
	$(clang_compile) sa_string.cpp		-o build/sa_string.o
	$(clang_compile) sa_baseapplication.cpp	-o build/sa_baseapplication.o
	$(clang_compile) sa_random.cpp		-o build/sa_random.o

	ar rcs build/libsophia.a		\
		build/sa_math.o			\
		build/sa_sophia.o		\
		build/sa_stringtools.o		\
		build/sa_string.o		\
		build/sa_baseapplication.o	\
		build/sa_random.o

 

(My Test Application)

clang_compile = clang++ -std=c++0x -I ../libsophia/public/ -l:../libsophia/build/libsophia.a

all:
	$(clang_compile) main.cpp		-o build/main

 

 

I want to mention I know nothing about writing software in Linux, and any help would be much appreciated!

Thank you!

 

0

Share this post


Link to post
Share on other sites

OK! We made some progress, now "nm" gives the proper results.

 

However, I'm still getting the same amount of undefined references somehow. Am I linking to the lib properly in the "clang++" call?

 

 

I should also mention that this code is working in windows, so I'm pretty sure it's not a code error.

0

Share this post


Link to post
Share on other sites

Hmm, still no dice it would seem.

 

Here is how I compile the sophia static library:

clang++ -std=c++0x -c sa_math.cpp		-o build/sa_math.o
clang++ -std=c++0x -c sa_sophia.cpp		-o build/sa_sophia.o
clang++ -std=c++0x -c sa_stringtools.cpp	-o build/sa_stringtools.o
clang++ -std=c++0x -c sa_string.cpp		-o build/sa_string.o
clang++ -std=c++0x -c sa_baseapplication.cpp	-o build/sa_baseapplication.o
clang++ -std=c++0x -c sa_random.cpp		-o build/sa_random.o
In file included from sa_random.cpp:4:
In file included from ./SFMT-src-1.4/SFMT.h:67:
./SFMT-src-1.4/SFMT-params.h:7:4: warning: #warning "SFMT_MEXP is not defined. I assume MEXP is 19937." [-W#warnings]
  #warning "SFMT_MEXP is not defined. I assume MEXP is 19937."
   ^
1 warning generated.
ar rcs build/libsophia.a		\
		build/sa_math.o			\
		build/sa_sophia.o		\
		build/sa_stringtools.o		\
		build/sa_string.o		\
		build/sa_baseapplication.o	\
		build/sa_random.o

 

 

Here is what happens when I attempt to compile the test application:

clang++ -std=c++0x -I ../libsophia/public/ -L ../libsophia/build -lsophia  main.cpp		-o build/main
/tmp/main-bh2HIY.o: In function `main':
main.cpp:(.text+0x48e): undefined reference to `sa::Random::Random()'
main.cpp:(.text+0x49c): undefined reference to `sa::Random::Seed(unsigned int)'
main.cpp:(.text+0x4c8): undefined reference to `sa::Random::GetFloat64(double, double)'
main.cpp:(.text+0x4f9): undefined reference to `sa::Random::GetFloat64(double, double)'
main.cpp:(.text+0x52a): undefined reference to `sa::Random::GetFloat64(double, double)'
main.cpp:(.text+0x57a): undefined reference to `sa::String::GetCString() const'
main.cpp:(.text+0x5bd): undefined reference to `sa::String::~String()'
main.cpp:(.text+0x5dd): undefined reference to `sa::Random::~Random()'
main.cpp:(.text+0x617): undefined reference to `sa::String::~String()'
main.cpp:(.text+0x629): undefined reference to `sa::Random::~Random()'
/tmp/main-bh2HIY.o: In function `sa::Vector3<float>::GetString(int) const':
main.cpp:(.text._ZNK2sa7Vector3IfE9GetStringEi[_ZNK2sa7Vector3IfE9GetStringEi]+0x27): undefined reference to `sa::String::String()'
main.cpp:(.text._ZNK2sa7Vector3IfE9GetStringEi[_ZNK2sa7Vector3IfE9GetStringEi]+0x4e): undefined reference to `sa::String::Copy(float const*, unsigned int, unsigned int)'
main.cpp:(.text._ZNK2sa7Vector3IfE9GetStringEi[_ZNK2sa7Vector3IfE9GetStringEi]+0x82): undefined reference to `sa::String::~String()'
main.cpp:(.text._ZNK2sa7Vector3IfE9GetStringEi[_ZNK2sa7Vector3IfE9GetStringEi]+0x90): undefined reference to `sa::String::~String()'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [all] Error 1

 

 

I'm only testing it by instantiating an instance of the Random class and using it to fill a Vector3 (which is a template and so has no linking issues).

String is popping up because I try and get a String of the Vector's values to print out.

 

So I think everything that could be undefined is undefined.

0

Share this post


Link to post
Share on other sites

That helped!

Now I just have multiple definition issues. But at least that's more familiar territory.

james@debian:~/Dropbox/Fly Games/project_sophia/test$ clang++ -std=c++0x -I ../libsophia/public/ main.cpp -o build/main -L ../libsophia/build -lsophia
../libsophia/build/libsophia.a(sa_string.o): In function `sa::MemShiftForward(void*, unsigned int, unsigned int, unsigned int)':
sa_string.cpp:(.text+0x160): multiple definition of `sa::MemShiftForward(void*, unsigned int, unsigned int, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x1a0): first defined here
../libsophia/build/libsophia.a(sa_string.o): In function `sa::MemShiftBackward(void*, unsigned int, unsigned int, unsigned int)':
sa_string.cpp:(.text+0x1c0): multiple definition of `sa::MemShiftBackward(void*, unsigned int, unsigned int, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x200): first defined here
../libsophia/build/libsophia.a(sa_string.o): In function `sa::Free(void*)':
sa_string.cpp:(.text+0x80): multiple definition of `sa::Free(void*)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0xc0): first defined here
../libsophia/build/libsophia.a(sa_string.o): In function `sa::Calloc(unsigned int)':
sa_string.cpp:(.text+0x20): multiple definition of `sa::Calloc(unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x60): first defined here
../libsophia/build/libsophia.a(sa_string.o): In function `sa::Malloc(unsigned int)':
sa_string.cpp:(.text+0x0): multiple definition of `sa::Malloc(unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x40): first defined here
../libsophia/build/libsophia.a(sa_string.o): In function `sa::MemSet(void*, unsigned char, unsigned int)':
sa_string.cpp:(.text+0xa0): multiple definition of `sa::MemSet(void*, unsigned char, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0xe0): first defined here
../libsophia/build/libsophia.a(sa_string.o): In function `sa::MemCopy(void const*, void*, unsigned int)':
sa_string.cpp:(.text+0xe0): multiple definition of `sa::MemCopy(void const*, void*, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x120): first defined here
../libsophia/build/libsophia.a(sa_string.o): In function `sa::MemMove(void*, void*, unsigned int)':
sa_string.cpp:(.text+0x120): multiple definition of `sa::MemMove(void*, void*, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x160): first defined here
../libsophia/build/libsophia.a(sa_string.o): In function `sa::Realloc(void*, unsigned int)':
sa_string.cpp:(.text+0x50): multiple definition of `sa::Realloc(void*, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x90): first defined here
../libsophia/build/libsophia.a(sa_string.o): In function `unsigned int samath::RoundUpToPowerOfTwo<unsigned int>(unsigned int)':
sa_string.cpp:(.text+0x210): multiple definition of `unsigned int samath::RoundUpToPowerOfTwo<unsigned int>(unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x250): first defined here
../libsophia/build/libsophia.a(sa_string.o): In function `double samath::Random<double>(double, double)':
sa_string.cpp:(.text+0x360): multiple definition of `double samath::Random<double>(double, double)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x3a0): first defined here
../libsophia/build/libsophia.a(sa_string.o): In function `float samath::Random<float>(float, float)':
sa_string.cpp:(.text+0x290): multiple definition of `float samath::Random<float>(float, float)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x2d0): first defined here
../libsophia/build/libsophia.a(sa_random.o): In function `sa::MemShiftForward(void*, unsigned int, unsigned int, unsigned int)':
sa_random.cpp:(.text+0x160): multiple definition of `sa::MemShiftForward(void*, unsigned int, unsigned int, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x1a0): first defined here
../libsophia/build/libsophia.a(sa_random.o): In function `sa::MemShiftBackward(void*, unsigned int, unsigned int, unsigned int)':
sa_random.cpp:(.text+0x1c0): multiple definition of `sa::MemShiftBackward(void*, unsigned int, unsigned int, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x200): first defined here
../libsophia/build/libsophia.a(sa_random.o): In function `sa::Free(void*)':
sa_random.cpp:(.text+0x80): multiple definition of `sa::Free(void*)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0xc0): first defined here
../libsophia/build/libsophia.a(sa_random.o): In function `sa::Calloc(unsigned int)':
sa_random.cpp:(.text+0x20): multiple definition of `sa::Calloc(unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x60): first defined here
../libsophia/build/libsophia.a(sa_random.o): In function `sa::Malloc(unsigned int)':
sa_random.cpp:(.text+0x0): multiple definition of `sa::Malloc(unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x40): first defined here
../libsophia/build/libsophia.a(sa_random.o): In function `sa::MemSet(void*, unsigned char, unsigned int)':
sa_random.cpp:(.text+0xa0): multiple definition of `sa::MemSet(void*, unsigned char, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0xe0): first defined here
../libsophia/build/libsophia.a(sa_random.o): In function `sa::MemCopy(void const*, void*, unsigned int)':
sa_random.cpp:(.text+0xe0): multiple definition of `sa::MemCopy(void const*, void*, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x120): first defined here
../libsophia/build/libsophia.a(sa_random.o): In function `sa::MemMove(void*, void*, unsigned int)':
sa_random.cpp:(.text+0x120): multiple definition of `sa::MemMove(void*, void*, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x160): first defined here
../libsophia/build/libsophia.a(sa_random.o): In function `sa::Realloc(void*, unsigned int)':
sa_random.cpp:(.text+0x50): multiple definition of `sa::Realloc(void*, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x90): first defined here
../libsophia/build/libsophia.a(sa_stringtools.o): In function `sa::MemShiftForward(void*, unsigned int, unsigned int, unsigned int)':
sa_stringtools.cpp:(.text+0x160): multiple definition of `sa::MemShiftForward(void*, unsigned int, unsigned int, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x1a0): first defined here
../libsophia/build/libsophia.a(sa_stringtools.o): In function `sa::MemShiftBackward(void*, unsigned int, unsigned int, unsigned int)':
sa_stringtools.cpp:(.text+0x1c0): multiple definition of `sa::MemShiftBackward(void*, unsigned int, unsigned int, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x200): first defined here
../libsophia/build/libsophia.a(sa_stringtools.o): In function `sa::Free(void*)':
sa_stringtools.cpp:(.text+0x80): multiple definition of `sa::Free(void*)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0xc0): first defined here
../libsophia/build/libsophia.a(sa_stringtools.o): In function `sa::Calloc(unsigned int)':
sa_stringtools.cpp:(.text+0x20): multiple definition of `sa::Calloc(unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x60): first defined here
../libsophia/build/libsophia.a(sa_stringtools.o): In function `sa::Malloc(unsigned int)':
sa_stringtools.cpp:(.text+0x0): multiple definition of `sa::Malloc(unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x40): first defined here
../libsophia/build/libsophia.a(sa_stringtools.o): In function `sa::MemSet(void*, unsigned char, unsigned int)':
sa_stringtools.cpp:(.text+0xa0): multiple definition of `sa::MemSet(void*, unsigned char, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0xe0): first defined here
../libsophia/build/libsophia.a(sa_stringtools.o): In function `sa::MemCopy(void const*, void*, unsigned int)':
sa_stringtools.cpp:(.text+0xe0): multiple definition of `sa::MemCopy(void const*, void*, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x120): first defined here
../libsophia/build/libsophia.a(sa_stringtools.o): In function `sa::MemMove(void*, void*, unsigned int)':
sa_stringtools.cpp:(.text+0x120): multiple definition of `sa::MemMove(void*, void*, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x160): first defined here
../libsophia/build/libsophia.a(sa_stringtools.o): In function `sa::Realloc(void*, unsigned int)':
sa_stringtools.cpp:(.text+0x50): multiple definition of `sa::Realloc(void*, unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x90): first defined here
../libsophia/build/libsophia.a(sa_stringtools.o): In function `unsigned int samath::RoundUpToPowerOfTwo<unsigned int>(unsigned int)':
sa_stringtools.cpp:(.text+0x210): multiple definition of `unsigned int samath::RoundUpToPowerOfTwo<unsigned int>(unsigned int)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x250): first defined here
../libsophia/build/libsophia.a(sa_stringtools.o): In function `double samath::Random<double>(double, double)':
sa_stringtools.cpp:(.text+0x360): multiple definition of `double samath::Random<double>(double, double)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x3a0): first defined here
../libsophia/build/libsophia.a(sa_stringtools.o): In function `float samath::Random<float>(float, float)':
sa_stringtools.cpp:(.text+0x290): multiple definition of `float samath::Random<float>(float, float)'
/tmp/main-lSPKsO.o:main.cpp:(.text+0x2d0): first defined here
../libsophia/build/libsophia.a(sa_random.o): In function `sa::Random::Seed(unsigned int)':
sa_random.cpp:(.text+0x29a): undefined reference to `sfmt_init_gen_rand'
../libsophia/build/libsophia.a(sa_random.o): In function `sfmt_genrand_uint32':
sa_random.cpp:(.text+0x2fd): undefined reference to `sfmt_gen_rand_all'
../libsophia/build/libsophia.a(sa_random.o): In function `sfmt_genrand_uint64':
sa_random.cpp:(.text+0x3d9): undefined reference to `sfmt_gen_rand_all'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

 

It could be I made a mistake when moving over form "#pragma once" to the ifndef method somewhere but I tried to be careful and like I said in MSVC it builds without a warning.

 

Progress!

0

Share this post


Link to post
Share on other sites

I fixed it!
 

It was because I had a define that used __inline (from MSVC) and clang was just ignoring it.

 

Thanks for all your help guys.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0