KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
How can I use a static library in a C++ program that I have created? For example, lets say I preform the following actions: 1. First I create file: foo.h , and add the following code: int foo(int a); 2. In turn I create foo.cpp , and I add the following: #include foo.h int foo(int a) { return a+1; } 3. Then I use GNU's C++ compiler GCC (except I use the G++ version) which looks something like the following: 3a. g++ foo.cpp 3b. ar rc libfoo.a foo.o 4. I create my program's main file, main.cpp File: "main.cpp" #include "foo.h" int main() { int i = foo(2); return i; } Here is where I am getting an error. How can I compile my .a static library with main.cpp ? What I am attempting to do is the following: g++ -L. -lfoo prog.cpp but get an error because the function foo would not be found
Tags (comma-separated)
Save Edits
Cancel