I am trying to compile glfw with cygwin but getting errors like this
../src/glfw3.lib(win32_monitor.c.obj):win32_monitor.c:(.text+0x8a): undefined reference to `__imp_CreateDCW'
../src/glfw3.lib(win32_monitor.c.obj):win32_monitor.c:(.text+0x8a): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `__imp_CreateDCW'
Can someone help here ?
Anyone has successfull experience in compiling glfw with cygwin ?
Have you linked the libraries opengl32 and glfw3dll? Also have you included glad.h in your code? If so you should also include windows.h. Include the files in this order:
#include <windows.h>
#include <path_to_glad/glad.h>
#include <path_to_glfw/glfw3.h>
Then compile the code like this:
gcc/g++ main.c glad.c -lglfw3dll -lopengl32
It would also be better if you included your code along with your question
Related
I recently changed to Linux Mint Debian Edition and cannot include boost to Clion using cmake. Yesterday I tried every option I could find, including on stackoverflow, but nothing has worked yet.
Boost has been installed using: sudo apt -y install libboost-filesystem-dev
This is a version I found in this thread: How to include external library (boost) into CLion C++ project with CMake?
which supposedly worked, but it didn't.
cmake_minimum_required(VERSION 3.22)
project(boost_project)
set(CMAKE_CXX_STANDARD 14)
find_package(Boost COMPONENTS system filesystem REQUIRED)
if(Boost_FOUND)
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
message(STATUS "Boost_VERSION: ${Boost_VERSION}")
include_directories(${Boost_INCLUDE_DIRS})
endif()
add_executable(boost_project main.cpp)
if(Boost_FOUND)
target_link_libraries(boost_project ${Boost_LIBRARIES})
endif()
The Cmake output message is:
CMake Error at /app/extra/clion/bin/cmake/linux/share/cmake-3.22/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
Could NOT find Boost (missing: Boost_INCLUDE_DIR system filesystem)
I've gone through dozens of threads but so far nothing has worked. Has anyone suggestions of what's wrong?
EDIT:
So I've de-installed Clion and re-installed it with snap, since I read in another thread that it was an issue with installing Clion through the software center. Now I can include boost with no problem, but building it reveals the compiler still doesn't like using it.
#include <iostream>
#include "boost/asio.hpp"
boost::asio::io_service io_s;
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
: && /usr/bin/c++ -g CMakeFiles/BoostTest.dir/main.cpp.o -o BoostTest && :
/usr/bin/ld: CMakeFiles/BoostTest.dir/main.cpp.o: in function boost::asio::detail::posix_event::posix_event()': /usr/include/boost/asio/detail/impl/posix_event.ipp:42: undefined reference to pthread_condattr_setclock'
/usr/bin/ld: CMakeFiles/BoostTest.dir/main.cpp.o: in function boost::asio::detail::posix_thread::~posix_thread()': /usr/include/boost/asio/detail/impl/posix_thread.ipp:35: undefined reference to pthread_detach'
/usr/bin/ld: CMakeFiles/BoostTest.dir/main.cpp.o: in function boost::asio::detail::posix_thread::join()': /usr/include/boost/asio/detail/impl/posix_thread.ipp:42: undefined reference to pthread_join'
/usr/bin/ld: CMakeFiles/BoostTest.dir/main.cpp.o: in function boost::asio::detail::posix_thread::start_thread(boost::asio::detail::posix_thread::func_base*)': /usr/include/boost/asio/detail/impl/posix_thread.ipp:59: undefined reference to pthread_create'
/usr/bin/ld: CMakeFiles/BoostTest.dir/main.cpp.o: in function boost::asio::detail::posix_signal_blocker::posix_signal_blocker()': /usr/include/boost/asio/detail/posix_signal_blocker.hpp:43: undefined reference to pthread_sigmask'
/usr/bin/ld: CMakeFiles/BoostTest.dir/main.cpp.o: in function boost::asio::detail::posix_signal_blocker::~posix_signal_blocker()': /usr/include/boost/asio/detail/posix_signal_blocker.hpp:50: undefined reference to pthread_sigmask'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
The solution to the first problem, cmake not finding boost, had nothing to do with cmake but Clion. Installing Clion with flatpak can apparently cause this error. To fix it I just needed to de-install Clion and re-install it with snap.
The second issue was cmake not finding several thread related includes. For that cmake needed
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
to be added. I found this solution in these threads:
linking errors for boost for visual studio linux project
Undefined reference to pthread_create in Linux
The complete and working cmake looks like this now:
cmake_minimum_required(VERSION 3.22)
project(boost_project)
message(STATUS "start running cmake...")
find_package(Boost COMPONENTS system)
if(Boost_FOUND)
message(STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost_LIBRARIES: ${Boost_LIBRARIES}")
message(STATUS "Boost_VERSION: ${Boost_VERSION}")
set(CMAKE_CXX_STANDARD 14)
add_executable(boost_project main.cpp)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif()
target_link_libraries(boost_project ${Boost_LIBRARIES})
I'm having some trouble compiling a OpenCL aplication. When I run:
gcc -L/usr/include/CL -lOpenCL opencl-app.c -o out -lm
I receive the message:
/usr/bin/ld: cannot find -lOpenCL
The library exists, cause, when I run:
sudo find / -iname "*opencl*"
I receive :
/var/cache/apt/archives/opencl-headers_1.2-2013.10.23-1_all.deb
/var/lib/dpkg/info/opencl-headers.md5sums
/var/lib/dpkg/info/opencl-headers.list
/usr/include/CL/opencl.h
/usr/share/lintian/overrides/opencl-headers
/usr/share/doc/opencl-headers
/home/opuser/OpenCL
I'm including in the code this way:
#ifdef APPLE
#include <OpenCL/opencl.h>
#else
#include <CL/opencl.h>
#endif
I'm Using ubuntu 14.04. What can I do? Thanks!
I am running a simple C program having fork() call with cygwin environment using gcc compiler. It compiles well but while writing gcc Filename.c it shows error as:
$ gcc A.c
C:\cygwin\tmp\ccEkivvm.o:A.c:(.text+0x24): undefined reference to `fork'
collect2: ld returned 1 exit status
Can't we use fork() with cygwin on windows?
Did you forget to include the header
#include <unistd.h>
?
To the best of my knowledge, that would define fork() when using Cygwin.
Also, take a look at this question, you might be having the same problem:
Problem compiling program using fork in cygwin
I'm trying to get a "Hello World" application compiled for an ARM target. I'm cross compiling using gcc on Ubuntu/VMWare. If I compile for the host machine, it works fine. When I compile for the target, I get this error:
/root/picokernel/toolchain/arm-eabi/lib/libcs3hosted.a(hosted-sbrk.o): In function `_sbrk':
sbrk.c:(.text+0x74): undefined reference to `__cs3_heap_limit'
/root/picokernel/toolchain/arm-eabi/lib/libcs3hosted.a(hosted-sbrk.o):(.data+0x0): undefined reference to `__cs3_heap_start'
make: *** [HelloWorld] Error 1
So I think I need to link something in - perhaps my toolchain does not have the right libs? I was able to build the kernel, so I thought it was complete. Thanks! This is the target board. - runs Angstrom or Android.
makefile:
CC=$(CROSS_COMPILE)gcc
LD=$(CROSS_COMPILE)ld
CROSS_LIB1=/root/picokernel/toolchain/arm-eabi/lib
CROSS_LIB2=/root/picokernel/toolchain/lib/gcc/arm-eabi/4.2.1
CFLAGS=-Wall
LDFLAGS= -L$(CROSS_LIB1) -L$(CROSS_LIB2) -lc -lcs3hosted -lg -lgcc --entry main
HelloWorld: HelloWorld.o
$(LD) HelloWorld.o $(LDFLAGS)
clean:
rm -f HelloWorld HelloWorld.o
program:
#include <stdio.h>
int main(int argc, char **argv)
{
printf("Hello World\n");
return 0;
}
I gotta say, this is suspicious: -nostdlib
How about not using this flag?
The kernel does not use the C runtime library since the library does many—if not most—things not permitted by kernel code like file i/o and allocating memory.
Normally, you don't have to specify a library at all. gcc assumes the right thing. Try removing setting LDFLAGS altogether: I bet it works better.
Ok - finally worked this out, picked up a toolchain from the source here:
http://www.codesourcery.com/sgpp/lite/arm/portal/release1803
Hello World works great! Thanks for the suggestions
Does the toolchain you are using have a library called "lcs3arm" ? If so, try adding that to the list. You can also try "-lcs3" itself
Out of interest, which version of GCC are you using here? (i.e. which CodeSourcery release)
WHen I compile this code, it shows me linker error
#include <curses.h>
#include <ncurses.h>
int main()
{ int ch;
raw(); /* Line buffering disabled */
}
Compiler error:
/tmp/ccY9Bug1.o: In function `main':
raw.c:(.text+0x12): undefined reference to `raw'
collect2: ld returned 1 exit status
I have checked that curses.h anf ncurses.h exists in /usr/include directory and there is even man page for raw on my linux system.
Please tell me how to correct this error.
Pass "-lcurses" or "-lncurses" or something like that to the linker.
gcc foo.c -lcurses
works for me.
You need to link with curses or ncurses library:
gcc yourcode.c -lcurses -lncurses