When building a shared library on AIX with xlc, you see this linker warning:
ld: 0711-224 WARNING: Duplicate symbol: __fe_def_env
To reproduce, use this source file fenvtest.c:
#include <fenv.h>
void exported_func() {
fenv_t f;
(void)fegetenv(&f);
}
Then run the following command:
$ xlc -G -o fenvtest.so -lm -Wl,-bexpfull fenvtest.c
ld: 0711-224 WARNING: Duplicate symbol: __fe_def_env
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
Generally the warning about __fe_def_env occurs when building a shared library and the linker option -bexpfull is used. See the linker documentation for more explanation of -bexpfull.
The symbol __fe_def_env is defined in /usr/include/fenv.h:
const fenv_t __fe_def_env = { FE_TONEAREST, 0, 0, 0, 0 };
so it is included in every object that includes fenv.h. For that reason, if when a shared object is built with -bexpfull or another option that exports __fe_def_env, this symbol will collide with the symbol of the same name in other files.
You can avoid the warning by:
Using -bexpall instead of -bexpfull
Customizing the export list to exclude __fe_def_env
That said, the warning is harmless and may be ignored.
Related
I have a header file included in the main but when I compile the main, I have an error saying that the linker failed.
I tried to find the object files but I cannot find them.
I think the problem may come from my machine. I am kind of a beginner so I don't know how to solve this
When I try compiling my code I get this error:
Undefined symbols for architecture x86_64:
"_intClassic", referenced from:
_main in main-53b7e4.o
"_intQuadrature", referenced from:
_main in main-53b7e4.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
#zwol #JonathanLeffer I have 3 files in my project main.c, integral.h
and integral.c. integral.c contains the code of the functions
intClassic and intQuadrature that allow me to calculate different
types of integral. In integral.h I declared the functions and
structures I use. Finally in the main I included integral.h .
Also $ gcc -o output file1.o file2.o can this command help me ?
In the same directory as your files, try running the command
gcc main.c integral.c -o integral
This should take the 2 files and compile them into a program called ./integral
I'm watching a video in an attempt to better understand object files. The presenter uses the following as an example of a program that produces a very simple object file:
extern "C" void _start() {
asm("mov $60, %eax\n"
"mov $24567837, %edi\n"
"syscall\n");
}
The program is compiled via
clang++ -c step0.cpp -O1 -o step0.o
and linked via
ld -static step0.o -o step0
I get this error message when trying to link:
Undefined symbols for architecture x86_64:
"start", referenced from:
-u command line option
(maybe you meant: __start)
ld: symbol(s) not found for inferred architecture x86_64
I don't pass the -u command line option, so I'm not sure why I'm getting that error message.
clang isn't removing an underscore, it's adding an underscore. Your program is actually exporting a __start symbol, but ld expects you to have a start symbol for your entry point, i.e. ld runs with -u start by default for your architecture.
You could disable this check in ld with -U start (which suppresses the error from the start symbol being undefined) or via -undefined suppress (which suppresses all undefined symbol errors). However, you will end up with an executable that does not have an entry point for your architecture, so the program won't actually work.
Instead of suppressing the error, I suggest controlling the symbol that clang chooses directly. You can tell clang what symbol to generate by using a standalone asm declaration:
void _start() asm ("start");
Make sure this standalone declaration is separate from the function definition.
You can read more about controlling the symbols generated by gcc here: https://stackoverflow.com/a/1035937/12928775
Also, as was pointed out in a comment to a similar answer, you will most likely want to use __attribute__((naked)) on the function definition to prevent clang from generating a stack frame on entry. See: https://stackoverflow.com/a/60311490/12928775
I tried to use LibSBMLSim as api in c language.
I referenced https://fun.bio.keio.ac.jp/software/libsbmlsim/ and installed both LibSBML and LibSBMLSim.Then I made c file like below:
/* Example C, C++ code */
#include "libsbmlsim/libsbmlsim.h"
int main(void) {
/*
* Simulate sbml.xml to time=20 with dt=0.1, print_interval=10
* by 4th-order Runge-Kutta Method.
*/
myResult *r = simulateSBMLFromFile("sbml.xml", 20, 0.1, 10, 0, MTHD_RUNGE_KUTTA, 0);
write_csv(r, "result.csv"); /* Export simulation result as CSV file */
free_myResult(r); /* Free Result object */
return 0;
}
And executed "gcc test.c -o test", but error has occurred. Error messages are below:
Undefined symbols for architecture x86_64:
"_free_myResult", referenced from:
_main in test-f56b85.o
"_simulateSBMLFromFile", referenced from:
_main in test-f56b85.o
"_write_csv", referenced from:
_main in test-f56b85.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I checked /usr/local/include/libsbmlsim/libsbmlsim.h, there specified free_myResult function.
I tried a lot but it doesn't work. Please help.
I checked /usr/local/include/libsbmlsim/libsbmlsim.h, there specified free_myResult function.
That only confirms that the prototypes are present. But when you compile, you need to tell what library to use to find those symbols. So you need to link with the library using -lsbmlsim and probably specify the location of where to search for the library using -L and the location of header files using -I too -- all these in your command line.
Alternatively you can use a Makefile. Have a look at the Makefile provided in the libsbmlsim's example.
I've been trying to compile a old game I wrote using OpenGl 2.1 and C. I wanted to try compiling it with Emscripten. So I went ahead and built the tools and SDK from sauce, compiled some test examples and everything checks out.
Long story short, Emscripten doesn't support old/non ES OpenGL too well (understandably) but then I read that Regal can work well as an interpreter.
Here's where I'm stuck, I have no clue how to combine the Regal. When I simply replace the GL, GLU and GLUT header references, I get the same Emscripten compiler warnings, just replaced with what seems to be the Regal equivalents:
warning: unresolved symbol: rglPopMatrix
warning: unresolved symbol: rglShadeModel
warning: unresolved symbol: glutGameModeString
warning: unresolved symbol: rglLightfv
warning: unresolved symbol: rglMatrixMode
warning: unresolved symbol: glutSolidSphere
warning: unresolved symbol: rglLoadIdentity
warning: unresolved symbol: rglClear
warning: unresolved symbol: glutSolidCube
warning: unresolved symbol: rglTranslatef
warning: unresolved symbol: rglRotatef
warning: unresolved symbol: glutEnterGameMode
warning: unresolved symbol: rglMaterialfv
warning: unresolved symbol: rglPolygonMode
warning: unresolved symbol: rglPushMatrix
warning: unresolved symbol: rglGetFloatv
warning: unresolved symbol: rglViewport
warning: unresolved symbol: rglEnable
Am I missing something simple or vital here? Even an explanation as to why this doesn't/shouldn't work would be awesome.
If I manage to get any further with this, will post an update.
P.S. Compiler tools I'm using - OS is Ubuntu 12.04, 32-bit
https://github.com/kripken/emscripten
https://github.com/p3/regal
EDIT 2
I'm fairly sure this is an issue linking with Regal, but I can't seem to find any sort of decent documentation or methods apart from the simple "Include GL/Regal.H" and "Link with libRegal.so" statements on the github page. When I built the Regal package I used the standard "make all" command. Would I need to do anything further than that?
EDIT 1
What my current makefile looks like
INCLUDES = -L/home/BlastingKap/TestLibs/regal-master/lib/linux -lRegal -lRegalGLU -lRegalGLUT -s LEGACY_GL_EMULATION=1 -s GL_UNSAFE_OPTS=0
VoxelCannon: VoxelCannon.c graphics.c visible.c graphics.h
./emcc VoxelCannon.c graphics.c visible.c -o VoxCannon.html $(INCLUDES)
To get rid from warnings unresolved symbol: rgl* you should compile Regal with REGAL_NAMESPACE=1. Even more for emscripten you should compile Regal for emscripten. Use this command:
emmake make -f Makefile SYSTEM=emscripten
After that add to linker static libs from lib/emscripten (libRegallib).
P.S. I also trying to use Regal+emscripten, and I successfully build my project. However when I run it I does not see anything.
UPD. You should call RegalMakeCurrent((RegalSystemContext)1); to associate emscripten gl context with regal gl context. Like this:
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(0, 0);
glutInitWindowSize(width, height);
glutCreateWindow("app");
RegalMakeCurrent((RegalSystemContext)1);
glutDisplayFunc(draw);
I'm trying to set up default compiler, linker, etc for a build script. I currently have this:
CC="gcc -std=gnu99 -c"
XX="g++ -std=gnu++11 -c"
LD="gcc"
This works fine, but gives me no warning if I accidentally pass a .c file to $LD, leaving a landmine for anyone who tryes to use a different LD. I'd like to use LD="gcc -x [object]", but gcc documentation doesn't list any name to use for [object]. (I've also tryed LD="ld" of course, but that produces such lovely errors as ld: cannot find -lstdc++ and (after adding -lc) ld: warning: cannot find entry symbol _start; defaulting to 0000000000400e60.)