I am trying to build Shared Object (.so) files for the ImageMagick library however stuck due to following error while creating .so file
[arm64-v8a] Executable : magick
ld: error: undefined symbol: aligned_alloc
>>> referenced by memory.c:262 (././ImageMagick-7.0.9-17/MagickCore\memory.c:262)
>>> memory.o:(AcquireAlignedMemory) in archive ./obj/local/arm64-v8a/libmagickcore-7.a
>>> referenced by memory.c:262 (././ImageMagick-7.0.9-17/MagickCore\memory.c:262)
>>> memory.o:(AcquireVirtualMemory) in archive ./obj/local/arm64-v8a/libmagickcore-7.a
>>> referenced by memory.c:262 (././ImageMagick-7.0.9-17/MagickCore\memory.c:262)
>>> memory.o:(AcquireVirtualMemory) in archive ./obj/local/arm64-v8a/libmagickcore-7.a
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [C:/hostedtoolcache/windows/ndk/r22b/x64/build//../build/core/build-binary.mk:741: obj/local/arm64-v8a/magick] Error 1
Error: Process completed with exit code 1.
I have very basic knowledge on c++, any suggestions are welcome if I am missing something.
Here's GitHub Actions link where I am generating .so file and facing error for ease of reproducing the issue.
https://github.com/malaythecool/Android-ImageMagick7/runs/2316777388?check_suite_focus=true
From the CI logs, it shows up
././ImageMagick-7.0.9-17/MagickCore/memory.c:262:10: warning: implicit declaration of function 'aligned_alloc' is invalid in C99 [-Wimplicit-function-declaration]
which finally ends up in the linker complaining for the missing symbol
ld: error: undefined symbol: aligned_alloc
Try adding the flag -std=c++1z to your build configuration since aligned_alloc() was introduced in C++17.
EDIT:
It seems the Application.mk already sets the -std=c++17 here. Could you try adding the following flag too:
APP_CONLYFLAGS += -std=c11
to ensure that the C standard is updated to C11 wherein alloc_aligned() was introduced?
Related
I am new to C++, and trying to use get_string, but I am not sure what I writing wrong that is creating an error.
The code I have is the following:
#include <stdio.h>
#include <cs50.h>
int main(void)
{
string name = get_string("What's your name? ");
printf("hello, %s\n", name);
}
and it keeps saying the following error:
Undefined symbols for architecture arm64:
"_get_string", referenced from:
_main in hello-890d43.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [hello] Error 1
Does any one know what I am doing wrong?
I expected the code take an input and print out hello, (your input).
The same thing happened to me when trying to use the cs50 C library on my local Mac with M1 chip.
Even after installing the library as described here: https://cs50.readthedocs.io/libraries/cs50/c/
It still didn't work.
The problem is coming from the fact that the make command here doesn't include the link command by default.
Assuming your source file is named hello.c instead of just doing:
make hello
You have to enter the following in your terminal in order to compile:
clang hello.c -o hello -lcs50
Afterwards, when running the executable, it works as expected:
./hello
make hello LDLIBS="-lcs50"
LDLIBS to include the cs50 library
I'm using clang 7 in windows and linux to generate coverage on c++ project.
In linux I can successufuly generate all coverage information simply by adding compilation flags:
-fprofile-instr-generate -fcoverage-mapping
But in windows it returns me linker errors and also llvm-cov does not exist in llvm installation dir...
So i'm guessing that clang does not support code coverage in windows? is this right?
(if not can you tell me what i'm missing in linkage stage?)
PS: linker errors go from:
lld-link.exe: error: duplicate symbol: __profn_??_GTestFactoryBase#internal#testing##UEAAPEAXI#Z
to:
lld-link.exe: error: undefined symbol: __llvm_profile_runtime
>>> referenced by src\app\CMakeFiles\app.dir\main.cpp.obj:(__llvm_profile_runtime_user)
lld-link.exe: error: undefined symbol: __llvm_profile_register_function
>>> referenced by src\app\CMakeFiles\app.dir\main.cpp.obj:(__llvm_profile_register_functions)
>>> referenced by src\app\CMakeFiles\app.dir\main.cpp.obj:(__llvm_profile_register_functions)
PS: i'm using visual studio Build Tools to compile with clang in windows.
PS2: from what i read we need to pass "-fprofile-instr-generate" to the linker also... but don't know how this should be done...
Thanks
on windows you should use clang-cl.exe with --coverage option.
This link will help you to do that...
https://marco-c.github.io/2018/01/09/code-coverage-with-clang-on-windows.html
I am trying to compile my C++ code in Windows cmd.
I have implemented UnitTest++ in the project. When I run:
g++ main.cpp -IC:\Test\TreeObjModel\include -IC:\Test\unittest-cpp-master\UnitTest++
it gives the following error:
undefined reference to `UnitTest::RunAllTests()' collect2.exe: error:
ld returned 1 exit status
Can anyone help me to resolve this? Is any more info needed?
You probably are missing to compile some other cpp file (UnitTest.cpp?); or maybe you must link to some UnitTest library, where the code for UnitTest::RunAllTests() resides.
The command line option for linking a library with GCC is -l library_name.
I'm trying to learn FLTK for C++ and I'm working on a Macbook with the clang++ compiler. Whenever I try to link the library like this:
clang++ -L/usr/local/lib -lfltk
It gives me this error:
clang: warning: argument unused during compilation: '-X11'
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've looked on a couple other forums to see how to fix this problem and haven't gotten any answers that worked. I also tried reinstalling Command Line Tools from Apple's Developer site.
You have to make sure you put the linker command (-L/usr/local/lib -lfltk) before doing filename.cpp -o Exectuable but still in the same line in the command line.
I've been developing with CentOS, Qt 4.7, and GCC 4.4
I've just installed Red Hat Developer Toolset 1.1 which includes GCC 4.7.2, and at the end of make, I get an error
/usr/bin/ld: ../../bin/Solo: undefined reference to symbol 'pthread_rwlock_trywrlock##GLIBC_2.2.5'
/usr/bin/ld: note: 'pthread_rwlock_trywrlock##GLIBC_2.2.5' is defined in DSO /lib64/libpthread.so.0 so try adding it to the linker command line
/lib64/libpthread.so.0: could not read symbols: Invalid operation
collect2: error: ld returned 1 exit status
I'm guessing that Qt threads is referencing to that. How can I fix it?
You want to compile with -pthread which does more than just link with libpthread:
Adds support for multithreading with the pthreads library. This
option sets flags for both the preprocessor and linker.
You just need to add CONFIG += thread to your .pro file.
Read the note: try to add /lib64/libpthread.so.0 into Makefile (-lpthread after gcc command, or /lib64/libpthread.so.0 after ld (or after gcc -shared)), or something like LIB += -lpthread if there's such definition somewhere.
See also: Adding external library into Qt Creator project and http://www.qtcentre.org/threads/39144-How-to-add-a-lib-to-a-qt-project
Btw, post your Makefile, so somebody will be able to point to exact line.
In my little laptop Linux (where I have a mixed bag of libraries),
I just had to add
LDFLAGS=-lpthread
AT THE END of the configure command arguments.
After that, make did its job perfectly (With the existing libraries).
I received similar 'Linker error: undefined reference to symbol' errors attempting to compile and install Python-3.7.2 on FreeBSD 12.
/usr/bin/ld: error: undefined symbol: _Py_GetGlobalVariablesAsDict
/usr/bin/ld: error: undefined symbol: _PyCoreConfig_AsDict
/usr/bin/ld: error: undefined symbol: _PyMainInterpreterConfig_AsDict
Resolved by passing LDFLAGS=-lpthread directly to make of lang/python37 or by adding to /etc/make.conf.
If using portmaster to install/update use -m to pass the arguement to make e.g.portmaster -a -m 'LDFLAGS=-lpthread'