-7

I have created a .lib file that should generate random integers into an array and print them out. The array is then sorted into lowest to highest and then printed again. I am able to compile all the object files and create a library with them, but am unsure how to execute the file itself.

2 Answers2

0

A compiler cannot execute a .lib file.

You need to link the .lib into an executable with main defined. You can have your main function call the function in the .lib.

Please consider reading references on how a compiler works, such as this: https://msdn.microsoft.com/en-us/library/91621w01.aspx

This might also help you: https://msdn.microsoft.com/en-us/library/ba1z7822.aspx

JDiMatteo
  • 12,022
  • 5
  • 54
  • 65
-1

A .lib is a static library file, and static libraries cannot be executed by their very nature - they are only a library, not an application. They are instead imported by another C application (that's one thing that #include statements do) and used.

This link has more information. Also, JDiMatteo's links are good references on the topic. (Check his answer - I don't want to duplicate links from his answer.)

NOTE: The rules are largely the same for both C and C++ on this.

CodeMouse92
  • 6,840
  • 14
  • 73
  • 130