Creating your own and using C++ libraries Creating your own and using C++ libraries
\n1) Create the files "mylibrary.h" and "mylibrary.cpp".
\n2) Only compile the library, and it shouldn’t have a "main()" function in it. This step will generate an object file called "myfile.o".
\n3) Create another file called something like "main.cpp". In main.cpp you need to #include<\/a> "mylibrary.h".
\n4) Compile main.cpp and add the library from step 2 to link in (in this case "myfile.o"). If you don’t add this library, you’ll get a error message like "linker error – can’t find function definition", or something like that.<\/p>\nTC1017 #Mastery14<\/a><\/h1>\n<\/div>\n","protected":false},"excerpt":{"rendered":"
\n1) Create the files “mylibrary.h” and “mylibrary.cpp”.
\n2) Only compile the library, and it shouldn’t have a “main()” function in it. This step will generate an object file called “myfile.o”.
\n3) Create another file called something like “main.cpp”. In main.cpp you need to #include<\/a> “mylibrary.h”.
\n4) Compile main.cpp and add the library from step 2 to link in (in this case “myfile.o”). If you don’t add this library, you’ll get a error message like “linker error – can’t find function definition”, or something like that.<\/p>\nTC1017 #Mastery14<\/a><\/h1>\n<\/div>\n