I have a problem with include files in Xcode, while I am compiling a gstreamer project.
The header search path contains :
"/Library/Frameworks/GStreamer.framework/Versions/0.10/Headers"
When I am including a header file :
#include <gst/gst.h> the CMD+click function to follow the link answer me " SYMBOL NOT FOUND ".
Moreover, I have compilation problems, I am sure the reason is here.
Thanks
Related
I wanted to try out the WXWidgets Hello World example (https://docs.wxwidgets.org/latest/overview_helloworld.html) so I followed the recommended practice on the Downloads page and installed the WXGTK package for my distribution, Ubuntu, which appears to be libwxgtk3.0-gtk3-dev. After doing this, and copying the example code, g++ (installed from build-essentials) throws an error when I attempt to compile the program:
wxtest.cpp:4:10: fatal error: wx/wxprec.h: No such file or directory
4 | #include <wx/wxprec.h>
| ^~~~~~~~~~~~~
compilation terminated.
My editor (VSCode) also shows me an error: cannot open source file "wx/wxprec.h".
This appears to be related to the fact that the WXWidgets header files are installed to the folder wx-3.0/wx instead of wx, but after changing #include <wx/wxprec.h> to #include <wx-3.0/wx/wxprec.h> I still get an error:
In file included from wxtest.cpp:4:
/usr/include/wx-3.0/wx/wxprec.h:12:10: fatal error: wx/defs.h: No such file or directory
12 | #include "wx/defs.h"
| ^~~~~~~~~~~
compilation terminated.
What am I doing wrong? How can these files be put in the right place?
See the building your project section of the docs.
I am trying to utilize the ffmpeg libraries in a program of my own and am having trouble linking them. Specifically, In my a basic program I am receiving fatal error LNK1120: 1 unresolved externals errors. The program is:
#include <iostream>
#include <libswresample/swresample.h>
int main()
{
std::cout << "Hello World!\n";
struct SwrContext* swr_ctx = swr_alloc();
if (!swr_ctx) {
std::cout << "Could not allocate resampler context";
}
}
I downloaded prebuild libraries from https://ffmpeg.zeranoe.com/builds/, specifically the Windows x64 dev package which includes the .def/.lib as well as .dll files.
I originally tried (and intend to ultimately use) cmake to generate the MSVC sln files. The cmake file is:
cmake_minimum_required(VERSION 3.5)
project(ffmpeg_jni)
# Find the JNI bits
find_package(JNI)
# Search for the ffmpeg libraries
set(ffmpeg_include_hint "ffmpeg-dev/include")
set(ffmpeg_lib_hint "ffmpeg-dev/lib")
find_path(SWRESAMPLE_INCLUDE_DIR libswresample/swresample.h PATHS ${ffmpeg_include_hint})
find_library(SWRESAMPLE_LIBRARY swresample PATHS ${ffmpeg_lib_hint})
add_library(swresample SHARED IMPORTED)
set_target_properties(swresample PROPERTIES
IMPORTED_LOCATION "${SWRESAMPLE_LIBRARY}"
IMPORTED_IMPLIB "${SWRESAMPLE_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${SWRESAMPLE_INCLUDE_DIR}"
)
# Setup basic include dirs
set(includeDIRS
src/main/cpp
${JAVA_INCLUDE_PATH})
# Setup windows specific includes
set(includeDIRS
${includeDIRS}
${JAVA_INCLUDE_PATH}/Win32)
include_directories(${includeDIRS})
set(WRAPPER_SRC
src/main/cpp/logging.c
src/main/cpp/logging.h
src/main/cpp/main.cpp)
add_library(ffmpeg_jni SHARED ${WRAPPER_SRC})
target_link_libraries(ffmpeg_jni PRIVATE swresample)
The generated solution compiles and has proper access to the include files (Visual Studio can even take me to the declarations). The issue comes in the linking phase of the build where I receive:
error LNK2019: unresolved external symbol "struct SwrContext * __cdecl
swr_alloc(void)" (?swr_alloc##YAPEAUSwrContext##XZ) referenced in
function main
Thinking that I perhaps had something wrong in cmake since I am still pretty new with it I tried making a simple demo as a pure visual studio project following what I have found in countless online demos for adding an external library to a project. Specifically this included:
Adding the directory containing the header files to Properties->C/C++->General->Additional Include Directories
Adding the directory containing the .lib files to Properties->Linker->General->Additional Library Directories (Note that the cmake path did not do this but instead added the lib file via a relative path)
Adding the .lib file to Properties->Linker->Input->Additional Dependencies
At this point any searching efforts I undertake show me different people doing the same things which tells me I've been looking at this too long to find the answer myself and its something trivial that I'm missing/not understanding.
If you are compiling your project as c++, then include FFmpeg headers as below which tells your c++ compiler to handle FFmpeg headers as C instead of C++.
extern "C" {
#include <libswresample/swresample.h>
}
-- Question solved --
This question is solved. Thanks for all the help!
The problem and the reason is briefly stated as following for other readers in the future:
[Environment]
Ubuntu 14.04, Bazel, C++
[Question]
I want to include an external library. So I download the source file and make it as as a static lib .a.
I correctly set the BUILD, WORKSPACE and related files. However, when compile, it alerts the error:
Linking of rule '//main' failed (Exit 1)
main: error: undefined reference to 'void ex_lib::compute(double*, double const*, double const*)'
collect2: error: ld returned 1 exit status
I tried with the .lo and alwayslink method here but doesn't work.
Alternate to "`--whole-archive`" in bazel
[Reason]
It is because that the external library source files contains duplicate header files. So I fix the header file problem. Make the .a again. Then everything works.
So nothing wrong with the bazel. It is the library itself that cause the problem. But the error information is confusing and I think it is caused by bazel.
What you can do to investigate further is to run the clean bazel build with --subcommands to see individual command lines of actions executed. Then you can cd into the sandbox, and execute the same gcc command as bazel does and debug what's wrong. Or you can try to get linking to work by handwriting gcc command, and pasting here both the command bazel generated, and your desired command. Is it possible that you have multiple liegroups libs installed on the system and gcc is getting one that's incompatible with headers you're including?
The problem is solved. Special thanks to mhlopko.
It is mainly because there is errors with the lib source file. Thus .a file I use contains errors. Now the bazel works fine with the new lib file.
By the way, now bazel works fine with both .a or .so file that I generated.
I'm trying to compile a SWIG project, and it keeps on giving errors like this:
swig_wrap.cpp(55): warning C4005: 'SWIGTEMPLATEDISAMBIGUATOR': macro
redefinition
And errors like this:
fatal error C1010: unexpected end of file while looking for precompiled
header. Did you forget to add '#include "stdafx.h"' to your source?
Compiler
Visual Studio 2015+Update 3.
SWIG v3.0.12
Add the following to your .i file:
%begin %{
#include "stdafx.h"
%}
This section injects code into the generated wrapper at the top of the file and you won't need to disable pre-compiled headers.
In Visual Studio, right click on the swig-generated .cpp wrapper file, and select "Not Using Precompiled Headers".
In my case, the wrapper file that swig auto-generated was swig_wrap.cpp.
You can leave precompiled headers on for the entire project.
For more info, see nabble.com and Fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
Appendix A: SWIG could be fixed to avoid this!
Another way to fix this is to manually add the line "stdafx.h" to the start of this file, but unfortunately, every time swig is run it will remove this fix! There is a way to fix this, but its not at all obvious (see the other answer).
I am encountering 'duplicate symbol' errors in Xcode 4.5.1 when I try to build a project after adding my own framework. I verified the framework files for duplicates and there are none. But when I add the framework to a project, it complains with these error. Please suggest..
duplicate symbol _NXArgc in:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/crt1.3.1.o
/Users/idcc/Test/MyFW/Products/MyTestFW.framework/MyTestFW
duplicate symbol _NXArgv in:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/crt1.3.1.o
/Users/idcc/Test/MyFW/Products/MyTestFW.framework/MyTestFW
duplicate symbol ___progname in:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/crt1.3.1.o
/Users/idcc/Test/MyFW/Products/MyTestFW.framework/MyTestFW
duplicate symbol _environ in:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/crt1.3.1.o
/Users/idcc/Test/MyFW/Products/MyTestFW.framework/MyTestFW
duplicate symbol start in:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/crt1.3.1.o
/Users/idcc/Test/MyFW/Products/MyTestFW.framework/MyTestFW
ld: 8 duplicate symbols for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Thanks in advance..
I had the same issue with using two third party framework. I resolved that by removing "all_load" from "Other Linker Flags" in build settings.
Those symbols are in crt.o, the startup code of standard C library. Normally it should be the entry point of executable file to initialize global variables and objects. It will also call your main function.
But for a framework, you should not include it in your binary because framework should not have main.
I believe you have "Link with Standard Library" option as "YES" in your framework's target build setting. This will link crt.o into your framework. And when you link the framework into a project, there will be duplicated symbols.
Please set the option "Link with Standard Library" to NO in your build setting.
Your application has provided an implementation in which there are 8 duplication symbols.
There are a number of ways you might have done this:
You have two modules declaring the same class. Perhaps one is no longer needed?
You are importing any header file in both the files .m and .h :-( Remove from one place.)
You are importing any .m file somewhere. :- (Import .h file instead of .m file)
You have defined and declared any const variable in outside(above) the #interface{} in any of .h file, it might being duplicated. :- (Do it in the .m file.)
Also check, if global variables like constants are defined correctly in .h file in application.
The correct way of defining global variable is to use extern variable in .h file.
Note :This is not an issue with the previous Xcode version. I faced the problem with Xcode 6.3 and it was solved.
If you have this problem only when you run the app in the simulator, it gets solved by deleting the local folder
~/Library/Developer/CoreSimulator
Xcode will restore it after the first build and run.
PLEASE MAKE SURE YOU BACKUP ANY SETTINGS before doing this (especially those related to simulator devices).
Tested on Xcode Version 7.2.1 (7C1002)