See also using MASM assembler instead of C - http://www.purebasic.fr/english/viewtop ... 4&p=489136
For OSX & Linux it's even easier - see http://www.purebasic.fr/english/viewtop ... 2&p=488178
For Windows ...
1. Start Visual Studio (im using VS2013 for this), and click File menu -> New Project
2. In \Installed\Templates\Visual C++\Win32, select Win32 Project
3. Type "testlib" in Name, and click Ok
4. Select Static Library, and uncheck the other boxes
5. Right-click "Source Files", click Add -> New Item, and type "testlib.c" (ensuring the extension is .c and not the default .cpp - I dont know if you can make C++ libs for PB, but C is obviously fine and thats what we'll make here)
6. Add the C source code of the library:
Code: Select all
double addnums(double num1, double num2) {
return num1 + num2;
}
8. Project menu -> Properties. Go to Configuration Properties\C/C++\Optimization, and ensure that "Whole Program Optimization" is turned OFF. You can still set the main Optimization to "Maximize Speed" or "Minimize Size" etc if you want and play around with all the other settings too it seems, but you can NOT use Whole Program Optimization with libs! (it's On by default!)
8b. Also, make sure to select "Disable C++ Security Checks"
9. Build menu -> Build Solution.
10. Copy the .lib file to wherever your .pb source file will be
11. Create the .pb source file:
Code: Select all
ImportC "testlib.lib" ;ensure ImportC and not Import
addnums.d (value1.d, value2.d) As "_addnums"
EndImport
MessageRequester("Result", StrD(addnums(5,2)))
See also your \Purebasic\SDK\ directory!
Anyone have any guides for Linux and OSX?!?
[minor edit] I changed the function name from "add" to "addnums", as while it was ok on Windows it was clashing on Linux due to "add" being an asm instruction - poor form on my behalf there!