Sign in to follow this  
BringBackFuturama

Compiling Using Make, GCC in C Langauge

Recommended Posts

Alright...you guys probably won't help me, but I'm desperate here and don't have very many resources. I'm trying to compile this program using MinGW, it's got like statically linked libraries and object files and all kinds of things. I'm using a makefile to compile it...here's what it looks like:
[SOURCE]
CC = gcc

all:
	make lib
	make app

app: main.o
	gcc -L main.o -oFillArray -oGetAverage -oGetCounts -oGetGrade -oGetGraph -oGetHigh -oGetLow -oGetStdDev -oGetVariance -oMoreData 	-oSortElements -lalan
main.o: main.c alan.h libalan.a

lib: FillArray.o GetAverage.o GetCounts.o GetGrade.o GetGraph.o GetHigh.o GetLow.o GetStdDev.o GetVariance.o MoreData.o SortElements.o
	ar -r libalan.a FillArray.o GetAverage.o GetCounts.o GetGrade.o GetGraph.o GetHigh.o GetLow.o GetStdDev.o GetVariance.o MoreData.o 	SortElements.o
FillArray.o: FillArray.c alan.h 
GetAverage.o: GetAverage.c alan.h
GetCounts.o: GetCounts.c alan.h 
GetGrade.o: GetGrade.c alan.h
GetGraph.o: GetGraph.c alan.h 
GetHigh.o: GetHigh.c alan.h
GetLow.o: GetLow.c alan.h
GetStdDev.o: GetStdDev.c alan.h 
GetVariance.o: GetVariance.c alan.h 
MoreData.o: MoreData.c alan.h
SortElements.o: SortElements.c alan.h
[/SOURCE]
Okay..now the issue I'm having is that is with the library libalan.a, located in the same place as the rest of the files, so you'd think it would find it. But instead it gives me this: gcc -L main.o -oFillArray -oGetAverage -oGetCounts -oGetGrade -oGetGraph -oGetHigh -oGetLow -oGetStd Dev -oGetVariance -oMoreData -oSortElements -lalan C:\Documents and Settings\(My Name)\My Documents\School\Clark\11th Grade\Quarter 2\Intro to C\MinG W\bin\..\lib\gcc-lib\mingw32\3.2.3\..\..\..\..\mingw32\bin\ld.exe: cannot find -lalan Where do I have to put this library to make it find it? Compilers confuse me!

Share this post


Link to post
Share on other sites
[SOURCE]
CC = gcc
OBJS = FillArray.o GetAverage.o GetCounts.o GetGrade.o GetGraph.o GetHigh.o GetLow.o GetStdDev.o GetVariance.o MoreData.o SortElements.o

all: lib app

app: main.o
gcc liblan.a main.o -o app

main.o: main.c alan.h libalan.a

lib: $(OBJS)
ar -r libalan.a $(OBJS)

FillArray.o: FillArray.c alan.h
GetAverage.o: GetAverage.c alan.h
GetCounts.o: GetCounts.c alan.h
GetGrade.o: GetGrade.c alan.h
GetGraph.o: GetGraph.c alan.h
GetHigh.o: GetHigh.c alan.h
GetLow.o: GetLow.c alan.h
GetStdDev.o: GetStdDev.c alan.h
GetVariance.o: GetVariance.c alan.h
MoreData.o: MoreData.c alan.h
SortElements.o: SortElements.c alan.h
[/SOURCE]


ok, try the above makefile, it should work...
the OBJS variable is optional it's just to make the reading easier, and the whole thing easier to maintain.

anyway, the problem of not finding the library, is that gcc is looking for the library names at the beginning of the compilation command.
if the above app command won't work, try out:
gcc -llan main.o -o app

aside from that you don't need all the -o(objfile) flags, you've already compiled them into a library, you don't need to link with them again.
other than that, all looks cool... hope it works out.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zar Sluzky
*** Source Snippet Removed ***[/source]

ok, try the above makefile, it should work...
the OBJS variable is optional it's just to make the reading easier, and the whole thing easier to maintain.

anyway, the problem of not finding the library, is that gcc is looking for the library names at the beginning of the compilation command.
if the above app command won't work, try out:
gcc -llan main.o -o app

aside from that you don't need all the -o(objfile) flags, you've already compiled them into a library, you don't need to link with them again.
other than that, all looks cool... hope it works out.


Alright, first of all, thanks a lot. But uh...it's still not working. Here's an altered version of what you gave me (I moved the stuff into folders, lib, bin, include, etc). I'm running the make file from a directory just below all of those.

[SOURCE]

CC = gcc
OBJS = src\FillArray.o src\GetAverage.o src\GetCounts.o src\GetGrade.o src\GetGraph.o src\GetHigh.o src\GetLow.o src\GetStdDev.o

src\GetVariance.o src\MoreData.o src\SortElements.o

all: lib app

app: src\main.o
gcc -llib\libalan.a src\main.o -o app src\main.o -o app

src\main.o: src\main.c include\alan.h lib\libalan.a

lib: $(OBJS)
ar -r libalan.a $(OBJS)

src\FillArray.o: src\FillArray.c include\alan.h
src\GetAverage.o: src\GetAverage.c include\alan.h
src\GetCounts.o: src\GetCounts.c include\alan.h
src\GetGrade.o: src\GetGrade.c include\alan.h
src\GetGraph.o: src\GetGraph.c include\alan.h
src\GetHigh.o: src\GetHigh.c include\alan.h
src\GetLow.o: src\GetLow.c include\alan.h
src\GetStdDev.o: src\GetStdDev.c include\alan.h
src\GetVariance.o: src\GetVariance.c include\alan.h
src\MoreData.o: src\MoreData.c include\alan.h
src\SortElements.o: src\SortElements.c include\alan.h

[\SOURCE]

It's still giving me the same error:

gcc -llib\libalan.a src\main.o -o app src\main.o -o app
C:\Documents and Settings\(MY NAME)\My Documents\School\Clark\11th Grade\Quarter 2\Intro to C\MinG
W\bin\..\lib\gcc-lib\mingw32\3.2.3\..\..\..\..\mingw32\bin\ld.exe: cannot find -llib\libalan.a


I'm seriously lost...and this assignment is due tommorow...CRAP!

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