Comments (14)
@alrevuelta will look into it.
from connxr.
I tried the mechanism with a minimal example and it works:
main.c
#include <stdio.h>
extern __attribute__((weak)) char* func(void);
int main() {
printf("func @ %p\n",func);
if (func) {
printf("func: %s\n", func());
} else {
printf("func not defined\n");
}
return 0;
}
func.c
char* func(void) {
return "hello";
}
$ gcc -std=c99 -c main.c -o main.o
$ gcc -std=c99 -c func.c -o func.o
$ gcc -std=c99 main.o -o no_func
$ ./no_func
func @ (nil)
func not defined
$ gcc -std=c99 main.o func.o -o func
$ ./func
func @ 0x55ff463ed1a2
func: hello
the extern __attribute__((weak))
line actually produces a function pointer, which is by default NULL
. when the linker finds a matching function it "updates" the pointer.
from connxr.
ah sorry, I misunderstood the problem
from connxr.
the address operators inside the return statements are wrong. the resolver should return the function pointer itself, not the address of the function pointer. will update the generator.
from connxr.
@nopeslide
Actually what I meant was your first reply. The third command is not working for me under macOS:
$ gcc -std=c99 main.o -o no_func
Undefined symbols for architecture x86_64:
"_func", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
After a quick search I found this where one of the solutions suggests to add the following flags -Wl,-flat_namespace,-undefined,dynamic_lookup
and that seems to work for me.
from connxr.
After a quick search I found this where one of the solutions suggests to add the following flags
-Wl,-flat_namespace,-undefined,dynamic_lookup
and that seems to work for me.
these flags are not present in my ld
. are these mac specific flags?
from connxr.
Looks like its mac specific. Seems also that its not really a good idea.
"Weak linking with weak_import really only works well with dynamic libraries. You can get it to work with static linking (by specifying -undefined dynamic_lookup as suggested above) but this isn't such a hot idea. It means that no undefined symbols will be detected until runtime. This is something I would avoid in production code, personally."
Will look further into this.
from connxr.
since we are building a static binary no symbol search should be done at runtime. could you pass the static
flag and see if it still does not work or if flat_namespace
is still needed?
from connxr.
are you developing on a mac? if not we could keep these flags and just trust the linux gcc to report any linker errors
from connxr.
If you mean something like:
gcc -std=c99 main.o -o no_func -static
I'm geetting:
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
And according to gcc
man:
This option will not work on Mac OS X unless all libraries (including libgcc.a) have also been compiled with -static. Since neither a static version of libSystem.dylib nor crt0.o are provided, this option is not useful to most people.
Yep, I'm developing on mac.
from connxr.
I looked at a few other projects with Mac ports (i.e. gcc). it seems they're all using these flags.
Could you try if the linker accepts missing hard refs with these flags by adding a function prototype and using it without defining the actual function?
If so, this would be a problem, if not we may use them.
Alternatively I could rewrite the Makefile to partially link everything operator related with these flags.
Hopefully this would allow "normal" linking of everything else
from connxr.
You mean these flags? -Wl,-flat_namespace,-undefined,dynamic_lookup
?
from connxr.
yes
from connxr.
Solved in #34
from connxr.
Related Issues (20)
- How to convert the model input to a .pb file?
- Two missing null check for return values of searchAttributeNyName()
- Help running inference using yolov5, 6 & 8 HOT 4
- remove/integrate old trace.{c,h} into tracing.h
- Add C++ ifdef inside header to disable mangling
- Github action windows build fails
- Wrong printf format string for type int32_t
- Support for hardware without file systems HOT 2
- Memory leaks HOT 4
- Add support for ConvTranspose2d
- Tracing not compatible with C99 HOT 4
- Benchmarking and time.h on Windows
- cannot find -lcunit HOT 2
- build fail on linux and mac HOT 5
- tiny yolov2 doesn't work on raspberry pi zero HOT 9
- src/inference.c line 29 HOT 1
- using macro function to reduce execute_operator_***.c file to single c source file HOT 1
- modify src/inference.c file target to resolve once and not depend on inputs HOT 1
- Add operator can be write in macro without type HOT 1
- example use other input HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from connxr.