Skip to content

Static Library output with Odin #3784

Answered by herohiralal
herohiralal asked this question in Q&A
Discussion options

You must be logged in to vote

Posting the complete solution here.

First, some info:

A .LIB file is a collection of .OBJ files concatenated together with an index. There should be no difference in how the linker treats either.

source

Here's the C++ file:

// main.cpp
#include <iostream>

extern "C" int UncoolMul(int a, int b)
{
    return a * b;
}

extern "C" {
    int CoolAdd(int a, int b);
    int CoolMul(int a, int b);
}

int main(int argc, char* argv[])
{
    std::cout << CoolAdd(3, 4) << '\n';
    std::cout << CoolMul(3, 4) << '\n';
    return 0;
}

Here's the Odin file:

// kk.odin
package main

import "core:fmt"

@export
CoolAdd :: proc "c" (a: i32, b: i32) -> i32 {
	return a + b
}

foreign {
    UncoolMul :: proc 

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@herohiralal
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by herohiralal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants